note 36420 added to function.imagecopymergegray
| From: | mail at laeubi dot de | Date: | Thu, 09 Oct 2003 04:45:22 +0000 |
| Subject: | note 36420 added to function.imagecopymergegray | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58085@lists.php.net to get a copy of this message | ||
This function don't work properly for me on trucolerimages (have not tried yet for other types)
it jsut produce a part-grayscale image, and some color get mesed up.
I found a workaround here:
http://www.phpbuilder.com/columns/cash20030526.php3?page=2
[quote]
Advanced Image Editing Under the GD Library
Colorizing
Colorizing images is fairly easy to do. The easiest way to colorize an image is fairly simple to
grasp. Create an image of the same dimensions and fill that image with the color you want to change
it to. This new image is then placed on top of the older image, giving it a colorized look.
<?php
function imagecolorize(&$im,&$col,$pct) {
// Get the image's width
$im_w = imagesx($im);
// Get the image's height
$im_h = imagesy($im);
// Set a pixel with the color, so we can get it easily
$setpixel = imagesetpixel($im,$im_w,0,$col);
// Get the color
$index = imagecolorat($im,$im_w,0);
// Find the color in the index
$rgb = imagecolorsforindex($im,$index);
// Get the red value
$r = $rgb["red"];
// Get the green value
$g = $rgb["green"];
// Get the blue value
$b = $rgb["blue"];
// Create the layover
$layover = imagecreate($im_w,$im_h);
// Allocate the color on this image
$color = imagecolorallocate($layover,$r,$g,$b);
// Fill the image with the new color (this really isn't needed)
$fill = imagefill($layover,0,0,$color);
// Merge the layover on top of the older image
$merge = imagecopymerge($im,$layover,0,0,0,0,$im_w,$im_h,$pct);
imagedestroy($layover); // Destroy the layover
}
?>
If we use a blue layover RGB(0,0,255), we get this result:
[/quote]
if you use black or gray, its not perfekt, but better than nothing ;)
----
Manual Page -- http://www.php.net/manual/en/function.imagecopymergegray.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36420
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36420&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36420&report=yes
Search -- http://master.php.net/manage/user-notes.php