Join David Powers for an in-depth discussion in this video Converting to a different image format, part of PHP: Resizing and Watermarking Images.
- [Voiceover] Most of the time when using PHP's GD functions…you'll want to preserve the output in the same image format…as the original, but you can also use PHP…to convert from one format to another.…To explain why you might want to do so,…I've come to CanIUse.com…Let's search for webp.…Webp is a great format for photographs…because the file size is usually much smaller…than JPEG without loss of quality.…But even though Webp has been around since 2010,…at the time of recording this video in mid-2016,…you can see that browser support is far from universal.…
So let's switch to my editing program, see how to do it.…I've got open here Convert.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