Connecting Tech Pros Worldwide Help | Site Map

Need help with a GD function

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:58 AM
somaBoy MX
Guest
 
Posts: n/a
Default 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



 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.