PDA

View Full Version : imagefilledrectange coordinates

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

tia.

delinear
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);

marek_mar
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:

<?php
function draw_rect(\$im, \$x, \$y, \$width, \$hight)
{
imagefilledrectangle(\$im, \$x, \$y, \$x + \$width, \$y + \$hight);
}
?>
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}