Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Use image_resize_dimensions to correctly downsize image styles #22
Image styles are about fitting the image in its original aspect ratio into the boundaries of current image style. So instead of using the image style size to determine which argument we should pass to getImageServingUrl, we should calculate the dimensions for the final image and find the argument from those values. Because of the possible differences in aspect ratios between the image style and the actual image, the resizing argument can be something else than either of the image style constraints.
We can use the same core function (image_resize_dimensions) that WordPress uses internally to determine these final image dimensions. The function also helps us to determine if current image style is not intermediate for the image and leave those options off as WordPress itself does.
The latest fix by tuanmh (#21) addresses the problem with captions (WordPress for some reason requires the pixel dimensions to be present for captions), but uses the image style size instead of the final image size which results in distorted images if the aspect ratios don't match.