Create public methods to specify output sizes and quality of JPEG and PNG images.
- [Voiceover] The next stage in building…the Resize Images class is to add public methods…to set the image sizes and quality.…From the technical point of view,…it doesn't matter which order, method, definitions…are listed in a class definition.…But I like to keep all public methods together…at the top, so I'm going to insert the Set Output Sizes…method after the constructor,…so scroll down, find the end of the Constructor.…There it is on line 43.…Add in some extra space and we're using public function…and we'll call it Set Output Sizes.…
This will take two arguments.…The first one needs to be an array,…so I'll use a type declaration for that.…Call it Sizes,…and the second argument will determine…whether to use the longer dimension for re-sizing.…In other words, to base the new size on the height…for images in Portrait Orientation.…So I'll call that, Use Longer Dimension.…And by default, I'll set it to True,…so that makes it an optional argument.…
Before assigning these sizes to the Output Sizes Property,…it's a good idea to check that each element…
Released
7/14/2016Chapter 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
Share this video
Embed this video
Video: Setting output sizes and quality