Jump to content

GD help


Renlok

Recommended Posts

Im trying (and failing) to make a pet recolouring script for a game.

 

<?php
//coords
$base_x = array(100);
$base_y = array(100);
$eyes_x = array(43, 20);
$eyes_y = array(83, 81);
$detail_x = array(20,24,28,39,34,39,48,44,57,56,95,91,98);
$detail_y = array(70,60,67,64,58,51,47,41,41,32,125,141,163);
//testing page
header ("Content-type: image/png");

$dogoverlay = imagecreatefrompng("images/misk-junk/dog-over.png");
$dogbase = imagecreatefrompng("images/misk-junk/dog-base.png");
$dogeyes = imagecreatefrompng("images/misk-junk/dog-eyes.png");
$dogdetails = imagecreatefrompng("images/misk-junk/dog-detail.png");
//get random colours to test with
$newcolour1 = imagecolorallocate($dogbase, 56, 160, 156);
$newcolour2 = imagecolorallocate($dogeyes, 253, 175, 4);
$newcolour3 = imagecolorallocate($dogeyes, 50, 207, 70);
$border = imagecolorallocate($dogbase, 10, 10, 10);
//recolour base
imagefilltoborder($dogbase, $base_x[0], $base_y[0], $border, $newcolour1);
//recolour eyes
for($i = 0; $i<count($eyes_x); $i++){
imagefilltoborder($dogeyes, $eyes_x[$i], $eyes_y[$i], $border, $newcolour2);
}
//recolour details
for($i = 0; $i<count($detail_x); $i++){
imagefilltoborder($dogeyes, $detail_x[$i], $detail_y[$i], $border, $newcolour3);
}

imagecopymerge($dogeyes,$dogbase,0,0,0,0,$width,$height,100);
imagecopymerge($dogdetails,$dogbase,0,0,0,0,$width,$height,100);
imagecopymerge($dogoverlay,$dogbase,0,0,0,0,$width,$height,100);
imagepng($dogbase,NULL,100); 
//clean up the image
imagedestroy($dogbase); 
imagedestroy($dogoverlay); 
imagedestroy($dogeyes); 
imagedestroy($dogdetails); 
?>

 

the problems i have are

- none of the images actually load up correctly, they either have a black background when its sposed to be transparent or they have random blobs of black in random places for no reason. No idea why this happens.

- all that shows is a wash off teal but i think thats caused because of the problems above.

 

and im new at using GD so i tend to make loads of really stupid mistakes. Also thanks in advance for any help.

Link to comment
Share on other sites

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.