468,296 Members | 1,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

Need help with a GD function

I found this function on PHPbuilder.net. It is supposed to colorize a JPEG
image by covering it with a transparent colored overlay. I'm trying to
implement it, but whatever color value I pass it always it always colorizes
the image in greyscale.

I'm probably passing the color values incorrectly, but I'm not sure what
kind of data the function is expecting. The page where I found the function
doesn't provide any solutions.

Any help would be extremely appreciated.
////////////////////////////////////////////////////////////////////////////
////////////////////////
Here's the function :
<?php
// function creates a layover in the specified color
// use it to output images in accordance with the basecolor
// of each issue

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,$p ct);
imagedestroy($layover); // Destroy the layover
return $merge;
}
?>
////////////////////////////////////////////////////////////////////////////
////////////////////////
Here's my implementation :
<?php
// split color value into rgb parts
$rgb = chunk_split('ff0000', 2);

// convert hex values to decimal
$rgb[0] = hexdec($rgb[0]);
$rgb[1] = hexdec($rgb[1]);
$rgb[2] = hexdec($rgb[2]);

$img = imagecreatefromjpeg('logoFM7201081767006.jpg');
$im = imagecolorize($img, $rgb, 20);
imagejpeg($img);
?>

Thank you,
..soma
Jul 17 '05 #1
0 1131

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Jeff Wagner | last post: by
8 posts views Thread by JustSomeGuy | last post: by
7 posts views Thread by brian.digipimp | last post: by
7 posts views Thread by Timothy Shih | last post: by
7 posts views Thread by fox | last post: by
8 posts views Thread by | last post: by
2 posts views Thread by Anders B | last post: by
9 posts views Thread by pereges | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.