note 31271 added to function.imagecolorallocate
| From: | leif at harmsen dot net | Date: | Wed, 16 Apr 2003 00:31:02 +0000 |
| Subject: | note 31271 added to function.imagecolorallocate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46665@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 ....
--
http://www.php.net/manual/en/function.imagecolorallocate.php
http://master.php.net/manage/user-notes.php?action=edit+31271
http://master.php.net/manage/user-notes.php?action=delete+31271
http://master.php.net/manage/user-notes.php?action=reject+31271