junaidbhura / fly-dynamic-image-resizer

Fly Dynamic Image Resizer plugin for WordPress
https://wordpress.org/plugins/fly-dynamic-image-resizer/
MIT License
161 stars 26 forks source link

permit image size height or width to be 0 #31

Closed kennithnichol closed 4 years ago

kennithnichol commented 4 years ago

WordPress permits passing 0 in for width or height to preserve the aspect ratio of the newly resized image.

The logic present in the add_image_size function retuns false because 0 is a falsey value in PHP.

The change will still prevent image sizes from being registered where both height and width are === 0.

Checklist:

ref issue #32

junaidbhura commented 4 years ago

Thanks @kennithnichol ! Let me take a look at this at length and get back to you!

junaidbhura commented 4 years ago

Hey @kennithnichol apologies for the super late response!

I've taken a look at this, and I think that we shouldn't encourage users to define width or height to be 0, as mentioned here:

https://developer.wordpress.org/reference/functions/add_image_size/

Although height and width are not required parameters, their default values (0) will lead to unwanted behavior, so bear in mind that you should always define them. As mentioned before, use a value of 9999 to define the other dimension as the one to be considered when image resize is executed.

So if users want to maintain the aspect ratio for an image, they could use a high number like 9999 as one of the sizes, rather than 0.

I'm gonna close this issue, but please feel free to continue the discussion here!