Drawing Lines

Before you draw a line on an image, you need to determine the points from and to which you want to draw.

You can think of an image as a block of pixels indexed from 0 on both the horizontal and vertical axes. The origin is the upper-left corner of the image.

In other words, a pixel with the coordinates 5, 8 is the sixth pixel along and the ninth pixel down, looking from left to right, top to bottom.

The imageline() function draws a line between one pixel coordinate and another. It requires an image resource, four integers representing the start and end coordinates of the line, and a color resource.

Listing 15.2 adds to the image created in Listing 15.1, drawing a line from corner to corner.

Listing 15.2. Drawing a Line with imageline() ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.