473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1282

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
7
by: brian.digipimp | last post by:
Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
8
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
32
by: lcdgoncalves | last post by:
Hi everyone Is there a real need to use keyword static with functions, if we simply don't declare their prototypes in .h file? Many textbooks avoid to discuss this matter and/or discuss only...
2
by: Anders B | last post by:
I want to make a program that reads the content of a LUA array save file.. More precicely a save file from a World of Warcraft plugin called CharacterProfiler, which dumps alot of information about...
9
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.