Jump to content

GD problem


Renlok

Recommended Posts

I'm trying to make a script where you can recolour an image how you want by applying colours different sections of an image and each section of the image is broken apart into its own image.

 

And im not very good at GD but i have this script

 

<?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");
list($width, $height, $type, $attr) = getimagesize("images/misk-junk/dog-over.png");
$background = imagecreate($width, $height);
//get random colours to test with
$newcolour1 = imagecolorallocate($background, 56, 160, 156);
$newcolour2 = imagecolorallocate($background, 253, 175, 4);
$newcolour3 = imagecolorallocate($background, 50, 207, 70);
$border = imagecolorallocate($background, 10, 10, 10);
//recolour base
$dogbase = imagefilltoborder($dogbase, $base_x[0], $base_y[0], $border, $newcolour1);
//recolour eyes
for($i = 0; $i<count($eyes_x); $i++){
$dogeyesar[] = imagefilltoborder($dogeyes, $eyes_x[$i], $eyes_y[$i], $border, $newcolour2);
}
//recolour details
for($i = 0; $i<count($detail_x); $i++){
$dogdetailsar[] = imagefilltoborder($dogeyes, $detail_x[$i], $detail_y[$i], $border, $newcolour3);
}
//stick it all together!

$background = imagecopymerge($background,$dogbase,0,0,0,0,$width,$height,100);
for($i = 0; $i<count($dogeyesar); $i++){
$background = imagecopymerge($background,$dogeyesar[$i],0,0,0,0,$width,$height,100);
}
for($i = 0; $i<count($dogdetailsar); $i++){
$background = imagecopymerge($background,$dogdetailsar[$i],0,0,0,0,$width,$height,100);
}
$background = imagecopymerge($background,$dogoverlay,0,0,0,0,$width,$height,100);
imagepng($dogbase,NULL,100); 
//clean up the image
imagedestroy($dogbase); 
imagedestroy($dogoverlay); 
imagedestroy($dogeyes); 
imagedestroy($dogdetails); 
?>

 

The errors it comes back with are

Warning: imagecopymerge(): supplied argument is not a valid Image resource in /home/welinkco/public_html/roeonline/test2.php on line 35

 

Warning: imagecopymerge(): supplied argument is not a valid Image resource in /home/welinkco/public_html/roeonline/test2.php on line 37

 

Warning: imagecopymerge(): supplied argument is not a valid Image resource in /home/welinkco/public_html/roeonline/test2.php on line 40

 

Warning: imagecopymerge(): supplied argument is not a valid Image resource in /home/welinkco/public_html/roeonline/test2.php on line 42

 

Warning: imagepng(): supplied argument is not a valid Image resource in /home/welinkco/public_html/roeonline/test2.php on line 43

 

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/welinkco/public_html/roeonline/test2.php on line 45

 

Thanks in advance for any help

Link to comment
https://forums.phpfreaks.com/topic/84138-gd-problem/
Share on other sites

not sure why your using an array from an image!?

$dogeyesar[] = imagefilltoborder($dogeyes, $eyes_x[$i], $eyes_y[$i], $border, $newcolour2);

 

infact imagefilltoborder returns a boolean, so it should be

imagefilltoborder($dogeyes, $eyes_x[$i], $eyes_y[$i], $border, $newcolour2);

 

same for $dogdetailsar[]

Link to comment
https://forums.phpfreaks.com/topic/84138-gd-problem/#findComment-428390
Share on other sites

not sure why your using an array from an image!?

$dogeyesar[] = imagefilltoborder($dogeyes, $eyes_x[$i], $eyes_y[$i], $border, $newcolour2);

 

infact imagefilltoborder returns a boolean, so it should be

imagefilltoborder($dogeyes, $eyes_x[$i], $eyes_y[$i], $border, $newcolour2);

 

same for $dogdetailsar[]

 

Cos im a noob :)

 

Well it does load all the images, but i check each of them by print each out. They dont load correctly though they just look like a black blob with random bits of white it. But ive still no idea how to fix the other errors.

 

Or how much would it cost me topay someone to code this script

Link to comment
https://forums.phpfreaks.com/topic/84138-gd-problem/#findComment-428535
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.