I have an image: image.png (could be jpg or gif)
How can I draw an 8x8 square at $x, $y
and then sa开发者_如何转开发ve the image to $file
?
You are looking for imagerectangle()
:
// Load the image
$img = imagecreatefrompng("image.png"); // or imagecreatefromjpeg(), etc.
// Set a colour for the sides of the rectangle
$color = imagecolorallocate($img, 255, 255, 255); // for a white rectangle
// Draw an 8x8 recangle at coordinates ($x, $y) from top left
imagerectangle($img, $x, $y, $x+8, $y+8, $color);
// Or, use imagefilledrectangle() with the same arguments if you want it filled
// Save the image
imagepng($img, "image.png"); // or imagejpeg(), etc.
精彩评论