Click to See Complete Forum and Search --> : Change Image with gd or imagmagick


acey99
06-09-2005, 04:13 PM
ok I have 2 images one with all of it's colors.

what I want to do is load that image with a script
eg :
[php]

# call this "overlay.php"

Header("Content-type: image/jpeg");
$im=imagecreatefromjpeg($Image);

define("WHITE",ImageColorAllocate($im, 0xFF,0xFF,0xFF));
define("BLACK",ImageColorAllocate($im, 0x0,0x0,0x0));
$fgColor=WHITE;
if ($color) {
$red=hexdec(substr($color,0,2));
$green=hexdec(substr($color,2,2));
$blue=hexdec(substr($color,4,2));
$fgColor=ImageColorAllocate($im, $red,$green,$blue);
}


# SOMETHING HERE

imagejpeg($im,'',80);
imagedestroy($im);

[\php]

but I want all of the colors in the original image to be replaced by the color sent to the script

eg : <img src="overlay.php?Image=SOMEIMAGE&color=FF0000" ... >

then output that image with the color (red in this case) over it.


any ideas with GD or imagemagick ?

acey99
06-09-2005, 04:51 PM
Here's the script for future use :


if ( !preg_match("/[3-6]/",$pg) ) $pg=3; # 3,4,5,6
$Image="images/ppg_".$pg.".jpg";
Header("Content-type: image/jpeg");
$im=($Image) ? imagecreatefromjpeg($Image) : imagecreatetruecolor(143,191); # 143x191
define("WHITE",ImageColorAllocate($im, 0xFF,0xFF,0xFF));
define("BLACK",ImageColorAllocate($im, 0x0,0x0,0x0));
define("tColor",ImageColorAllocate($im, 0x99,0x33,0xCC)); ##9933CC
$fgColor=tColor;
if ($color) {
$red=hexdec(substr($color,0,2));
$green=hexdec(substr($color,2,2));
$blue=hexdec(substr($color,4,2));
$fgColor=ImageColorAllocate($im, $red,$green,$blue);
}

imagelayereffect($im,IMG_EFFECT_OVERLAY);
imagefilledrectangle($im,0,0,142,190,$fgColor);

imagejpeg($im,'',80);
imagedestroy($im);