Created
April 2, 2011 20:05
-
-
Save wvega/899832 to your computer and use it in GitHub Desktop.
Patch for image_processing.php file from WP e Commerce 3.7.8 plugin to avoid cut off problems with thumbnails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/wp-content/plugins/wp-e-commerce/image_processing.php b/wp-content/plugins/wp-e-commerce/image_processing.php | |
| index c2c3d78..ecf2fb9 100644 | |
| --- a/wp-content/plugins/wp-e-commerce/image_processing.php | |
| +++ b/wp-content/plugins/wp-e-commerce/image_processing.php | |
| @@ -43,16 +43,21 @@ global $wpdb; | |
| $temp_w = $width; | |
| $temp_h = $height; | |
| // if the image is wider than it is high and at least as wide as the target width. | |
| - if (($source_h <= $source_w)) { | |
| - if ($height < $width ) { | |
| - $temp_h = ($width / $source_w) * $source_h; | |
| - } else { | |
| - $temp_w = ($height / $source_h) * $source_w; | |
| - } | |
| - //$temp_w = ($height / $source_h) * $source_w; | |
| - } else { | |
| - $temp_h = ($width / $source_w) * $source_h; | |
| - } | |
| +// if (($source_h <= $source_w)) { | |
| +// if ($height < $width ) { | |
| +// $temp_h = ($width / $source_w) * $source_h; | |
| +// } else { | |
| +// $temp_w = ($height / $source_h) * $source_w; | |
| +// } | |
| +// //$temp_w = ($height / $source_h) * $source_w; | |
| +// } else { | |
| +// $temp_h = ($width / $source_w) * $source_h; | |
| +// } | |
| + | |
| + // Resize ALWAYS keeping perspective - http://stackoverflow.com/questions/115462/proportional-image-resize | |
| + $ratio = min( (float) $width / (float) $source_w, (float) $height / (float) $source_h); | |
| + $temp_w = round($ratio * $source_w); | |
| + $temp_h = round($ratio * $source_h); | |
| // Create temp resized image | |
| // exit(get_option('product_image_height')); | |
| @@ -81,15 +86,19 @@ global $wpdb; | |
| ImageAlphaBlending($dst_img, TRUE ); | |
| imagecolortransparent($dst_img, $white); | |
| - | |
| + | |
| + // I replaced the code below with '($width - $temp_w) / 2, ($height - $temp_h)' | |
| + // in the ImageCopy call. That should center the resized image inside a thumbnail | |
| + // with the desired size - Willington Vega | |
| + | |
| // X & Y Offset to crop image properly | |
| - if($temp_w < $width) { | |
| - $w1 = ($width/2) - ($temp_w/2); | |
| - } else if($temp_w == $width) { | |
| - $w1 = 0; | |
| - } else { | |
| - $w1 = ($width/2) - ($temp_w/2); | |
| - } | |
| +// if($temp_w < $width) { | |
| +// $w1 = ($width/2) - ($temp_w/2); | |
| +// } else if($temp_w == $width) { | |
| +// $w1 = 0; | |
| +// } else { | |
| +// $w1 = ($width/2) - ($temp_w/2); | |
| +// } | |
| if($imagetype[2] == IMAGETYPE_PNG) { | |
| imagesavealpha($dst_img,true); | |
| @@ -99,7 +108,7 @@ global $wpdb; | |
| // Final thumbnail cropped from the center out. | |
| //ImageCopyResampled( $dst_img, $temp_img, 0, 0, $w1, $h1, $width, $height, $width, $height ); | |
| - ImageCopy( $dst_img, $temp_img, $w1, $h1, 0, 0, $temp_w, $temp_h ); | |
| + ImageCopy( $dst_img, $temp_img, ($width - $temp_w) / 2, ($height - $temp_h) / 2, 0, 0, $temp_w, $temp_h ); | |
| $image_quality = wpsc_image_quality(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment