开发者

How to draw an 8x8 square on an image?

开发者 https://www.devze.com 2022-12-13 13:25 出处:网络
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():

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消