2009-12-06 37 views
0

我有一个形象:image.png(可以是JPG或GIF)如何在图像上绘制8x8方格?

我怎样才能在$x, $y绘制一个8x8正方形,然后将图像保存到$file

+0

PHP imagick!将图像路径传递给新的imagick实例,绘制矩形writeImage,完成。 – markus 2009-12-06 10:51:41

回答

3

您正在寻找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.