note 31271 modified in function.imagecolorallocate by tomsommer
| From: | tomsommer@php.net | Date: | Fri, 16 Jul 2004 17:33:19 +0000 |
| Subject: | note 31271 modified in function.imagecolorallocate by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73409@lists.php.net to get a copy of this message | ||
I was unable to get any of the posted methods for converting colour to grayscale to work. The
problem appears to be the way gd creates images from jpeg inconsistently over various versions.
Eventually I wrote my own that works for me - this approach allocates the 256 color pallete first.
You can also play with separate $r, $g, $b variables before using imagecolorallocate in order to
tone or tint the image.
$resource = 'whatever.jpg';
$im_size = GetImageSize($resource);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];
$im = imageCreate($imageWidth,$imageHeight);
for ($c = 0; $c < 256; $c++) {
ImageColorAllocate($im, $c,$c,$c);
}
$im2 = ImageCreateFromJpeg($resource);
ImageCopyMerge($im,$im2,0,0,0,0, $imageWidth, $imageHeight, 100);
ImageDestroy($im2);
go on using $im as your image, it is now grayscale ....
--was--
I was unable to get any of the posted methods for converting colour to grayscale to work. The
problem appears to be the way gd creates images from jpeg inconsistently over various versions.
Eventually I wrote my own that works for me - this approach allocates the 256 color pallete first.
You can also play with separate $r, $g, $b variables before using imagecolorallocate in order to
tone or tint the image.
$resource = 'whatever.jpg';
$im_size = GetImageSize($resource);
$imageWidth = $im_size[0];
$imageHeight = $im_size[1];
$im = imageCreate($imageWidth,$imageHeight);
for ($c = 0; $c < 256; $c++) {
ImageColorAllocate($im, $c,$c,$c);
}
$im2 = ImageCreateFromJpeg($resource);
ImageCopyMerge($im,$im2,0,0,0,0, $imageWidth, imageHeight, 100);
ImageDestroy($im2);
go on using $im as your image, it is now grayscale ....
http://php.net/manual/en/function.imagecolorallocate.php