Jump to content

Recommended Posts

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.