Php 如何调整此函数以允许抖动?
我写了下面的函数。它把一种颜色换成另一种颜色。进入的图片是具有各种颜色和白色背景的css精灵 所以。。精灵1可能是蓝色的,精灵2可能是绿色的 该函数将运行两次,以将蓝色+绿色替换为所需的任何颜色Php 如何调整此函数以允许抖动?,php,gd,dithering,Php,Gd,Dithering,我写了下面的函数。它把一种颜色换成另一种颜色。进入的图片是具有各种颜色和白色背景的css精灵 所以。。精灵1可能是蓝色的,精灵2可能是绿色的 该函数将运行两次,以将蓝色+绿色替换为所需的任何颜色 /** * Changes the color of a graphic. * $settings = array ( * 'icon' * 'new_icon' * 'old_color' = array * 'new_color' = array * ); */ functio
/**
* 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);
}
我需要允许在这些图像上抖动。是否可以修改此函数以处理抖动图像或添加抖动本身?要在调色板转换中添加抖动,请更改:
imagetruecolortopalette($image, false, 255);
致:
要在调色板转换中添加抖动,请更改:
imagetruecolortopalette($image, false, 255);
致:
这样做对未抖动的精灵没有影响。将此参数添加到抖动的精灵会使它们变得不规则。这无助于颜色转换。抖动的结果取决于源图像中使用的颜色数量和第3个参数中指定的数量。然而,PHP手册指出,imagetruecolortopalette函数有时“工作得不如预期”……这样做对非抖动精灵没有影响。将此参数添加到抖动的精灵会使它们变得不规则。这无助于颜色转换。抖动的结果取决于源图像中使用的颜色数量和第3个参数中指定的数量。然而,PHP手册指出,imagetruecolortopalette函数有时“工作得不如人们所希望的那样好”。。。