vollyimnetz / crop-thumbnails

"Crop Thumbnails" made it easy to get exacly that specific image-detail you want to show. Crop your images the simple way.
GNU General Public License v3.0
47 stars 21 forks source link

adding conditional to determine file extension using new image_editor_output_format hook #54

Closed benjibee closed 3 years ago

benjibee commented 3 years ago

This small addition should allow the file extension of generated thumbnails to match the specified format for sub-sizes rather than the format of the original image.

Since WordPress 5.8 the image_editor_output_format hook makes it possible for generated thumbnails (sub-sizes) to be of a different image format than the original image. This is part of WordPress adding support for WebP, and eventually will also include other formats such as AVIF and JPEGXL.

It was a bit of a pain to get the extension from the file path so my method may not be the best. I tested it in various scenarios (including previous WordPress versions) and it falls back to JPG gracefully from what I can tell. If anyone has a better suggested fix I'd be happy to hear it!

Fixes #55

vollyimnetz commented 3 years ago

Hi @benjibee thank you for the contribution, i will try to test and use it as soon as posible. Im currently very busy with different projects - so please be patient.

vollyimnetz commented 3 years ago

@benjibee i reviewed the code. Seems to be OK, but can you provide an example where this is relevant? Has that to do with same filenames but different extensions?

benjibee commented 3 years ago

@vollyimnetz I know this PR was merged but just to be complete:

This would be relevant for anyone using WP 5.8 or greater that would like to upload JPEGs or PNGs and have the automatically generated thumbnails in another format (such as WebP). The current code assumes the file extensions of the original and generated images match one another.

Thanks! 👏