Changeset 9770 for extensions/square_thumbnails
- Timestamp:
- Mar 19, 2011, 1:24:41 PM (14 years ago)
- Location:
- extensions/square_thumbnails/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/square_thumbnails/trunk/functions.inc.php
r9757 r9770 43 43 $srcWidth = imagesx( $srcImage ); 44 44 $srcHeight = imagesy( $srcImage ); 45 $x = 0; 46 $y = 0; 47 48 if($srcWidth > $srcHeight) 49 { 50 $x = ceil(($srcWidth - $srcHeight) / 2 ); 51 $srcWidth = $srcHeight; 52 } 53 elseif ($srcHeight > $srcWidth) 54 { 55 $y = ceil(($srcHeight - $srcWidth) / 2); 56 $srcHeight = $srcWidth; 57 } 45 46 $coord = process_ratio($srcWidth, $srcHeight); 58 47 59 48 $ratioWidth = $srcWidth/$newWidth; … … 85 74 // GD 2.0 or more recent -> good results (but slower) 86 75 $destImage = imagecreatetruecolor( $destWidth, $destHeight); 87 imagecopyresampled( $destImage, $srcImage, 0, 0, $ x, $y,76 imagecopyresampled( $destImage, $srcImage, 0, 0, $coord['x'], $coord['y'], 88 77 $destWidth,$destHeight,$srcWidth,$srcHeight ); 89 78 } … … 92 81 // GD prior to version 2 -> pretty bad results :-/ (but fast) 93 82 $destImage = imagecreate( $destWidth, $destHeight); 94 imagecopyresized( $destImage, $srcImage, 0, 0, $ x, $y,83 imagecopyresized( $destImage, $srcImage, 0, 0, $coord['x'], $coord['y'], 95 84 $destWidth,$destHeight,$srcWidth,$srcHeight ); 96 85 } … … 195 184 $source_width = imagesx($source_image); 196 185 $source_height = imagesy($source_image); 197 $x = 0; 198 $y = 0; 199 200 if($source_width > $source_height) 201 { 202 $x = ceil(($source_width - $source_height) / 2 ); 203 $source_width = $source_height; 204 } 205 elseif ($source_height > $source_width) 206 { 207 $y = ceil(($source_height - $source_width) / 2); 208 $source_height = $source_width; 209 } 210 186 187 $coord = process_ratio($source_width, $source_height); 188 211 189 $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation); 212 190 … … 227 205 0, 228 206 0, 229 $ x,230 $ y,207 $coord['x'], 208 $coord['y'], 231 209 $resize_dimensions['width'], 232 210 $resize_dimensions['height'], … … 275 253 $source_height = $image->getImageHeight(); 276 254 277 // Crop image -> square 278 $x = 0; 279 $y = 0; 280 if($source_width > $source_height) 281 { 282 $x = ceil(($source_width - $source_height) / 2 ); 283 $source_width = $source_height; 284 } 285 elseif ($source_height > $source_width) 286 { 287 $y = ceil(($source_height - $source_width) / 2); 288 $source_height = $source_width; 289 } 290 $image->cropImage($source_width, $source_height, $x, $y); 255 $coord = process_ratio($source_width, $source_height); 256 257 $image->cropImage($source_width, $source_height, $coord['x'], $coord['y']); 291 258 292 259 $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation); … … 326 293 } 327 294 295 function process_ratio(&$source_width, &$source_height) 296 { 297 global $conf; 298 299 if (!isset($conf['thumbnails_ratio']) or !preg_match('/^\d+:\d+$/', $conf['thumbnails_ratio'])) 300 { 301 $conf['thumbnails_ratio'] = '1:1'; 302 } 303 304 $x = 0; 305 $y = 0; 306 307 if ($source_width >= $source_height) 308 list($widthRatio, $heightRatio) = explode(':', $conf['thumbnails_ratio']); 309 else 310 list($heightRatio, $widthRatio) = explode(':', $conf['thumbnails_ratio']); 311 312 $img_ratio = $source_width / $source_height; 313 $dest_ratio = $widthRatio / $heightRatio; 314 315 if($dest_ratio > $img_ratio) 316 { 317 $destHeight = ceil(($source_width * $heightRatio) / $widthRatio); 318 $y = ceil(($source_height - $destHeight) / 2 ); 319 $source_height = $destHeight ; 320 } 321 elseif ($dest_ratio < $img_ratio) 322 { 323 $destWidth = ceil(($source_height * $widthRatio) / $heightRatio); 324 $x = ceil(($source_width - $destWidth) / 2 ); 325 $source_width = $destWidth ; 326 } 327 328 return array('x' => $x, 'y' => $y); 329 } 330 328 331 add_event_handler('thumbnail_resize', 'thumbnail_square_resize', 40, 5); 329 332 add_event_handler('upload_thumbnail_resize', 'upload_square_resize', 40, 7); -
extensions/square_thumbnails/trunk/thumbnail.php
r9754 r9770 46 46 47 47 <li> 48 <span class="property"> {\'Square Thumbnails\'|@translate}</span>48 <span class="property"><label for="square">{\'Square Thumbnails\'|@translate}</label></span> 49 49 <label><input type="checkbox" name="square" id="square" {if $params.SQUARE}checked="checked"{/if}></label> 50 50 </li>
Note: See TracChangeset
for help on using the changeset viewer.