Skip to content

Commit

Permalink
fix issue with smaller widths
Browse files Browse the repository at this point in the history
  • Loading branch information
syamilmj committed May 6, 2012
1 parent 5811c8c commit a7602c8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
40 changes: 38 additions & 2 deletions aq_resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,53 @@ function aq_resize($url, $width, $height = null, $crop = null, $single=null) {
$ext = $info['extension'];
list($orig_w,$orig_h) = getimagesize($img_path);

//use original width if image is smaller than defined width

//get image size after cropping
$dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
$dst_w = $dims[4];
$dst_h = $dims[5];

//check if cropped image already exists, so we can return that instead
//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(file_exists($destfilename)) {

//if orig size is smaller
if($width >= $orig_w) {

$width = $orig_w;

if($crop) {

if(!$dst_h) :
$img_url = $url;
$dst_w = $width;
$dst_h = $orig_h;
else :

//check if cropped image already exists, so we can return that instead
$destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";

if(file_exists($destfilename)) {
$img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
} else {
$resized_img_path = image_resize( $img_path, $width, $height, $crop );
$resized_rel_path = str_replace( $upload_dir, '', $resized_img_path);
$img_url = $upload_url . $resized_rel_path;
}

endif;

} else {

$img_url = $url;

}
}
//else check if cache exists
elseif(file_exists($destfilename)) {
$img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
}
//else, we resize the image and return the new resized image url
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [Aqua Resizer](http://aquagraphite.com/)
### Version 1.0
### Version 1.1

This small script will allow you to resize & crop WordPress images uploaded via the media uploader. It relies on WP's native functions to resize the images, and checks if there is an already resized version of the image so that it won't be wasting your server's resources to regenerate the images.

Expand Down Expand Up @@ -116,6 +116,9 @@ Website: http://aquagraphite.com

## Changelog

**v1.1**
- fix issue with smaller widths

**v1.0**
first commit

Expand Down

0 comments on commit a7602c8

Please sign in to comment.