1

以下に関数を書きました。ある色を別の色に切り替えます。入ってくる写真は、さまざまな色と白い背景を持つ css スプライトです。

つまり、スプライト 1 は青で、スプライト 2 は緑である可能性があります。

関数は 2 回実行され、青 + 緑が必要な色に置き換えられます。

/**
 * Changes the color of a graphic.
 * $settings = array (
 *  'icon'
 *  'new_icon'
 *  'old_color' = array
 *  'new_color' = array
 * );
*/
function updateIconColor($settings=array()) {
    // Create Image
    $image = imagecreatefrompng($settings['icon']);

    // Convert True color image to a palatte
    imagetruecolortopalette($image, false, 255);

    // Restore Alpha
    $white = imagecolorclosest($image, 255, 255, 255);
    imagecolortransparent($image, $white);

    // Find + Set color
    $index = imagecolorclosest($image, $settings['old_color'][0],$settings['old_color'][1],$settings['old_color'][2]);
    imagecolorset($image, $index, $settings['new_color'][0], $settings['new_color'][1], $settings['new_color'][2]);

    // Restore Alpha
    imageAlphaBlending($image, true);
    imageSaveAlpha($image, true);

    // Save
    imagepng($image, $settings['new_icon']); // save image as gif
    imagedestroy($image);
}

これらの画像でディザリングを許可する必要があります。この関数を変更して、ディザリングされた画像に対処したり、ディザリング自体を追加したりする方法はありますか?

4

1 に答える 1

1

パレット変換でディザリングを追加するには、次のように変更します。

imagetruecolortopalette($image, false, 255);

に:

imagetruecolortopalette($image, true, 255);
于 2011-04-13T13:37:31.853 に答える