diff --git a/includes/resizer.php b/includes/resizer.php index 38a2bcb..353d90a 100644 --- a/includes/resizer.php +++ b/includes/resizer.php @@ -98,8 +98,6 @@ public function process( $url, $width = null, $height = null, $crop = null, $sin // Get image size after cropping. $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop ); - $dst_w = $dims[4]; - $dst_h = $dims[5]; // Return the original image only if it exactly fits the needed measures. if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) { @@ -107,17 +105,27 @@ public function process( $url, $width = null, $height = null, $crop = null, $sin $dst_w = $orig_w; $dst_h = $orig_h; } else { + + if ( ! $dims ) { + // Can't resize, so return false saying that the action to do could not be processed as planned. + return false; + } + + $dst_w = $dims[4]; + $dst_h = $dims[5]; + // Use this to check if cropped image already exists, so we can return that instead. $suffix = "{$dst_w}x{$dst_h}"; $dst_rel_path = str_replace( '.' . $ext, '', $rel_path ); $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}"; - if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) { + if ( ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) { // Can't resize, so return false saying that the action to do could not be processed as planned. return false; } + // Else check if cache exists. - elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) { + if ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) { $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}"; } // Else, we resize the image and return the new resized image url.