Join David Powers for an in-depth discussion in this video Using the exercise files, part of Resizing and Watermarking Images with PHP.
- [Voiceover] If you're a subscriber to the Linda.com online training library, you have access to the exercise files for this course. Just download them from the link on the course's page, and unzip them to a convenient location. I've got them here on my desktop. Let's take a quick look inside. The first two folders contain copies of the files used in each video. Most sub-folders in chapter one contain just two files: the script at the state of the beginning of the video, and the other showing what it looks like at the end.
The 01_05 and 01_06 folders are slightly different. They deal with embedding a watermark in resized images, and assume that you're using PHP5.5 or later. If you're using an older version of PHP, you'll need to use the files with resample in their names. They're based on a script developed earlier in the chapter, and are fully commented for you to study at your leisure. Chapter two builds a custom class that involves a lot of code.
Most sub-folders contain a copy of the class definition at the beginning, and at the end of the video. There's also usually a text file that contains code to be copied and pasted into the main file. Because this is a PHP course, all the files need to be copied into your server's document route. I created a folder called resize in my server root. The output, output two, and output three folders are where the resized images will be created. At the moment, they're empty, but PHP needs to be able to write to them.
On Windows, you don't need to do anything to make the writeable. On Mac OS 10, you might need to select each folder in the Mac Finder, press command I to bring up an info panel, and set the permissions for everyone to read and write. On Linux, set the permissions to 775, or 777, depending on your setup. Finally, the source folder contains a selection of images to practice with. They're different sizes, and a mixture of mime types.
The two images in portrait orientation have been chosen because PHP reports their width and height differently. The text file is simply there to test that the script in the final video in chapter two selects only images. So that's how the exercise files are organized. Let's get on with resizing and watermarking images with PHP.
Chapter 2 pulls everything together, using a custom PHP class that can batch process multiple images, automatically detect the correct MIME type, generate custom sizes, and add an optional watermark.
- Scaling an image with imagescale()
- Resizing an image with imagecopyresampled()
- Adding watermarks
- Correcting orientation
- Batch processing images