I wrote this code that was supposed to draw a black line of 1px at the bottom of an image, but it isn’t working as expected and it generates a totally black image:
$img = imagecreatefrompng("image.png");
$dest = imagecreatetruecolor(50, 25);
imagecopy($dest, $img, 0, 0, $px + $position[$pos][0], $py + $position[$pos][1] , 50, 25);
$w = imagesx($dest);
$h = imagesy($dest);
$out = ImageCreateTrueColor(imagesx($dest),imagesy($dest)) or die('Problem In Creating image');
for( $x=0; $x<$w; $x++) {
imagesetpixel($out, $x, $h, imagecolorallocate($out, 0, 0, 0));
}
Where’s the problem?
The problem is that you’re drawing your line on the
$outimage, which has nothing in it.$img(the original).$dest$imginto$dest$out$out.$outnever gets a copy of either the original or resized image, so it stays at the default all-black. You then draw a black line on a black image… ending up with a black image.