Created
April 20, 2010 19:49
-
-
Save yetti/372967 to your computer and use it in GitHub Desktop.
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
| //echo $imagefullpath; | |
| $img = ImageCreateFromJPEG($imagefullpath); | |
| $canvas = imagecreatetruecolor($thumb_w,$thumb_h); | |
| // following image calculation based on | |
| // http://return-true.com/2009/02/making-cropping-thumbnails-square-using-php-gd/ | |
| $orig_w = imagesx($img); | |
| $orig_h = imagesy($img); | |
| $w_ratio = ($thumb_w / $orig_w); | |
| $h_ratio = ($thumb_h / $orig_h); | |
| if ($orig_w > $orig_h) { // horizontal image | |
| $crop_w = $orig_w * $h_ratio; | |
| $crop_h = $thumb_h; | |
| } else if ($orig_w < $orig_h) { // vertical image | |
| $crop_w = $thumb_w; | |
| $crop_h = $orig_h * $w_ratio; | |
| } else { // already square | |
| $crop_w = $thumb_w; | |
| $crop_h = $thumb_h; | |
| } | |
| if (imagecopyresampled($canvas,$img,0,0,0,0,$crop_w,$crop_h,$orig_w,$orig_h)) { | |
| imagejpeg($canvas,$thumbfullpath, 100); | |
| } | |
| imagedestroy($canvas); | |
| imagedestroy($img); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment