syamilmj / Aqua-Resizer

Resize WordPress images on the fly
502 stars 208 forks source link

Last commit (WPML fix) broke the result when there is no image #91

Open rubenbristian opened 7 years ago

rubenbristian commented 7 years ago

Hi

In last commit you've removed the $result variable, which actually made sure that you get an image if the resize fails.. The fail can be caused by multiple reasons, even if the image exists. So now, if there is no resize, you get an empty string. This is obvious an error, which previously worked well..

Please return the $result variable.. Instead of a simple return it should be like this:

$result = $aq_resize->process( $url, $width, $height, $crop, $single, $upscale ); return $result !== false ? $result : $url;

Actually, this still breaks if the user requests an array. Because if he does, most probably he'll check for something like $resized_img[0], which will return the first letter of the string. So, a better solution would be something like this for the last line:

return $result !== false ? $result : ( $single ? $url : array( $url, $width, $height ) );

JonatanJJ commented 7 years ago

I would not consider your solution adequate in the case of $upscale being true. Also in case of $single being false the $width and $height returned in your example would not match the returned images dimensions, not sure if this is desired?

image_resize_dimensions will return false if $crop is false and the original image dimensions are less than those requested, no matter the value of $upscale. In this case aq_resize currently returns an empty result, and might even throw a PHP warning(?).

Aq_resize should either return an upscaled image or the original image.

benedikt-buchert commented 7 years ago

Also a little more helpful error would be great. Just had an image that was not resizing because it was simply to small. Took me a while to understand that the image was simply to small.

arawls-csu commented 6 years ago

@Jontis00 How do we resolve this error? I am experiencing this error currently.

JonatanJJ commented 6 years ago

@arawls-csu Have you tried version 1.2.2? Sounds like e00a662 tried to solve this issue, but I have not tested it myself.