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($i m,$im_w,0);
// Find the color in the index
$rgb = imagecolorsfori ndex($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 = imagecoloralloc ate($layover,$r ,$g,$b);
// Fill the image with the new color (this really isn't needed)
$fill = imagefill($layo ver,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($l ayover); // Destroy the layover
return $merge;
}
?>
////////////////////////////////////////////////////////////////////////////
////////////////////////
Here's my implementation :
<?php
// split color value into rgb parts
$rgb = chunk_split('ff 0000', 2);
// convert hex values to decimal
$rgb[0] = hexdec($rgb[0]);
$rgb[1] = hexdec($rgb[1]);
$rgb[2] = hexdec($rgb[2]);
$img = imagecreatefrom jpeg('logoFM720 1081767006.jpg' );
$im = imagecolorize($ img, $rgb, 20);
imagejpeg($img) ;
?>
Thank you,
..soma
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($i m,$im_w,0);
// Find the color in the index
$rgb = imagecolorsfori ndex($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 = imagecoloralloc ate($layover,$r ,$g,$b);
// Fill the image with the new color (this really isn't needed)
$fill = imagefill($layo ver,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($l ayover); // Destroy the layover
return $merge;
}
?>
////////////////////////////////////////////////////////////////////////////
////////////////////////
Here's my implementation :
<?php
// split color value into rgb parts
$rgb = chunk_split('ff 0000', 2);
// convert hex values to decimal
$rgb[0] = hexdec($rgb[0]);
$rgb[1] = hexdec($rgb[1]);
$rgb[2] = hexdec($rgb[2]);
$img = imagecreatefrom jpeg('logoFM720 1081767006.jpg' );
$im = imagecolorize($ img, $rgb, 20);
imagejpeg($img) ;
?>
Thank you,
..soma