View Full Version : imagefilledrectange coordinates

06-07-2005, 09:29 PM
I am trying to figure out imagefilledrectange, I am having a problem understanding x1,y1,x2,y2.

does anybody have a link to tutorial or more in depth explanation.


06-07-2005, 09:42 PM
x is the horizontal distance in pixels and y is the vertical distance in pixels.

x1 is the start position (ie the distance between the left hand side of your image and where you want the rectangle to start) and y1 is the distance from the top of your image that you want to start drawing. x2 is the distance from the left side of the image where you want the rectangle to end and y2 is the distance from the top where you want the image to end.

So, if you wanted a rectangle 100 pixels wide by 50 pixels tall starting in the very top left of your image you'd use:

imagefilledrectangle ($image, 0, 0, 100, 50, $colour);

Meanwhile if you wanted the same 100x50 pixel rectangle but you wanted it to be placed 10 pixels away from the left hand side and 5 pixels down from the top side of your image, you'd use:

imagefilledrectangle ($image, 10, 5, 110, 55, $colour);

06-07-2005, 11:42 PM
Imagine the image as a x, y graph (http://mathworld.wolfram.com/CartesianCoordinates.html). The 0,0 point (origin) is the top left corner.
The function draws a rectangle and takes two points as input not one point and width and height. If you'd wan't a function that can do that you could use this:

function draw_rect($im, $x, $y, $width, $hight)
imagefilledrectangle($im, $x, $y, $x + $width, $y + $hight);