Defvayne23

 

Posts Tagged ‘GD’

Use GD – 2a: Not Modified

When creating an image with PHP per call, why should the server have to create the image every time. In part two of using GD I’ll show how to use the 304 Not Modified header, and storing the image as cache.

To start we need to pass more info about the image from the previous post. Need to pass the last modified date and time, tell the browser that it can cache it and for how long, when the image would expire and an ID for the file.

41
42
43
44
45
header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($sFile))." GMT");
header("Pragma: public");
header("Cache-Control: maxage=".(60*60*24*2));
header("Expires: ".gmdate("D, d M Y H:i:s", strtotime("+2 days"))." GMT");
header("ETag: ".md5($sFile));

(more…)

Share

 

Use GD: Part 1 – Crop Image

This is the first in a series of accepting a users image, selecting the area, and cropping it. First we will start with the guts of the process and build on top of that.

When letting users upload images for a site, you normally would like the images to be the same ratio and size. To do this we need to crop the image. To get things started lets select the image.

Now that we have the image we need to load the image into GD before we can do anything with it. You can find all the GD functions we use here.
(more…)

Share