Join David Powers for an in-depth discussion in this video Introducing the GD extension, part of PHP: Resizing and Watermarking Images.
- [Voiceover] The GD extension for image creation…and manipulation is enabled in most popular PHP…distributions, but it's not part of the PHP core,…so you need to verify that it's enabled…on your server by running phpinfo.…Let's quickly do that.…We need to scroll down, it's past the core section,…and everything is listed in alphabetical order,…so we need to look for GD, there it is,…and this allows you to check…which types of images are supported.…
On my system the support to read and write gif,…or gif, depending on how you like to pronounce it,…there's also support for jpeg, for png, and for webp.…In other words, all the main image formats…supported by web browsers apart from SVG,…which is a text-based format.…There's also support for free-typed fonts.…Up here it says free-typed support…and it says that it's enabled.…In the unlikely event that GD isn't listed…on your system when you run phpinfo,…you'll need to ask your hosting company…or server administrator to enable it.…
Assuming GD is listed, let's take a look at what it does.…
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