kernelgpf Posted October 20, 2007 Share Posted October 20, 2007 I have the following script that replaces all red pixels on an image with a specified image tile, but I want to be able to swap the red with another hex color which I'll feed to the script. Could somebody show me how to do this? Thanks! $v=$_SERVER["DOCUMENT_ROOT"]; $skinfile = isset($_GET['skin']) ? $_GET['skin'] : "$v/Etc/dragonskins/bluewater.gif"; $skin = imagecreatetruecolor(500,508); $tile = imagecreatefromgif($skinfile); imagesettile($skin, $tile); imagefill($skin, 250, 205, IMG_COLOR_TILED); /** * convert dragon png to truecolor */ $im = imagecreatetruecolor(500,508); $dragon = imagecreatefrompng("$v/waterdragon.png"); imagecopy($im,$dragon,0,0,0,0,500,508); /** * select color to be replaced by skin */ $red = imagecolorat($im, 255,400); // coords of a red pixel for ($x=0; $x<500; $x++) { for ($y=0; $y<508; $y++) { if (imagecolorat($im,$x,$y) == $red) { $skinpix = imagecolorat($skin,$x,$y); imagesetpixel($im,$x,$y,$skinpix); } } } #header("content-type: image/png"); imagepng($im, 'bluedragon.png'); imagedestroy($im); imagedestroy($skin); imagedestroy($dragon); imagedestroy($tile); Link to comment https://forums.phpfreaks.com/topic/74022-solved-replace-one-color-with-another-in-an-image/ Share on other sites More sharing options...
kernelgpf Posted October 20, 2007 Author Share Posted October 20, 2007 ..bump. Link to comment https://forums.phpfreaks.com/topic/74022-solved-replace-one-color-with-another-in-an-image/#findComment-374089 Share on other sites More sharing options...
0x00 Posted October 20, 2007 Share Posted October 20, 2007 Surely your virtually there... http://uk3.php.net/manual/en/function.imagesetpixel.php Link to comment https://forums.phpfreaks.com/topic/74022-solved-replace-one-color-with-another-in-an-image/#findComment-374090 Share on other sites More sharing options...
kernelgpf Posted October 20, 2007 Author Share Posted October 20, 2007 Indeed, virtually. XP Thank you, I looked for it. Link to comment https://forums.phpfreaks.com/topic/74022-solved-replace-one-color-with-another-in-an-image/#findComment-374158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.