Reputation: 1613
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?
Upvotes: 1
Views: 382
Reputation: 360592
The problem is that you're drawing your line on the $out
image, which has nothing in it.
$img
(the original).$dest
$img
into $dest
$out
$out
.$out
never 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.
Upvotes: 1
Reputation: 1810
Your $y
isn't set, I think it's just a typo, you have set $h
, and used $y
instead.
Upvotes: 1