Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

php Image Functions

See sample.

The first image is a jpeg. I need to know the php image function coding to produce the 2nd image (with the green background) from the first.
Avatar of mms_master
mms_master
Flag of United Kingdom of Great Britain and Northern Ireland image

I don't know how to do this if the image is a jpeg sorry.
I'm not sure if its even possible. The only ways I can think of doing it with jpegs is to either replace the white colour for another colour; which could result in problems if there are other white ares in the image that shouldnt be replaced. Or to try to create a shape in the white areas and fill the shape with a new colour. But that means it would only fill that shape, and if you use a different image it wont work...

However if you can use gif images instead of jpeg images I have a solution for you.
Change your first image to a gif with a transparent background instead of a white background.
Then use the following php code
(Note: the output file is a gif, but it can be changed to jpeg as long as the first image is a gif)
<?php
 
function EditImage($image, $red, $green, $blue, $newfile) {
 
	$height = imagesy($image);
	$width = imagesx($image);
 
    $img = imagecreatetruecolor($width, $height);
    $col = imagecolorallocate($img, $red, $green, $blue);
	imagefill($img, 0, 0, $col);
	imagecopymerge($img, $image, 0, 0, 0, 0, $width, $height, 100);
	imagegif($img, $newfile);
	
 
}
 
header("Content-type: image/gif");
$NewImage = EditImage(imagecreatefromgif("merged4.gif"), 3, 108, 101, "newimage.gif");
echo "<html><body>";
echo "<img src='newimage.gif'>";
echo "</body></html>";
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial