Reply to GD_Image, imagecopyresample, dithering the transparent color

Your name:

Reply:


Posted by abc123456 on 10/22/07 06:42

Hello - I'm using imagecopyresample() to resize a GIF line-art type
image onto a polygon created with GD_Image in PHP. Each has a
transparent color (same color, I think!). The transparent color is
dithering during the resize, though. Result is, some pixels aren't
transparent anymore until I search the whole image for colors close
rgb-wise to the original transparent color, and put it back to
transparent. This color replacement step is a 400% performance hit in
my case (these aren't huge images).

Is there a way to just dither the non-transparent colors?

Or can I more easily find/replace the dithered colors back to the
original color? Here's the color replace function:

// replace a color with a new color
function change_color($image, $old_color, $new_color, $threshold) {
$image_width = imagesx($image);
$image_height = imagesy($image);

$r_old = ($old_color >> 16) & 0xFF;
$g_old = ($old_color >> 8) & 0xFF;
$b_old = $old_color & 0xFF;

// iterate through x axis
for ($x = 0; $x < $image_width; $x++) {

// iterate through y axis
for ($y = 0; $y < $image_height; $y++) {

// look at current pixel
$pixel_color = imagecolorat($image, $x, $y);

$rgb = imagecolorsforindex($image, $pixel_color );

$delta = abs( $rgb['red'] - $r_old ) + abs( $rgb['green'] -
$g_old ) + abs( $rgb['blue'] - $b_old );

// sum RGB deltas, and compare to thresh
if ( $delta <= $threshold && $delta != 0 ) {
// replace with new color
imagesetpixel($image, $x, $y, $new_color);
}

}
}
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация