Changeset 9754 for extensions/square_thumbnails/trunk/functions.inc.php
- Timestamp:
- Mar 18, 2011, 2:55:32 PM (14 years ago)
- Location:
- extensions/square_thumbnails/trunk
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
extensions/square_thumbnails/trunk/functions.inc.php
r9753 r9754 152 152 } 153 153 154 if (is_imagick()) 155 { 156 return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata); 157 } 158 else 159 { 160 return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality); 161 } 162 } 163 164 function upload_square_resize_gd($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality) 165 { 154 166 if (!function_exists('gd_info')) 155 167 { … … 163 175 if (in_array($extension, array('jpg', 'jpeg'))) 164 176 { 165 $source_image = @imagecreatefromjpeg($source_filepath);177 $source_image = imagecreatefromjpeg($source_filepath); 166 178 } 167 179 else if ($extension == 'png') 168 180 { 169 $source_image = @imagecreatefrompng($source_filepath);181 $source_image = imagecreatefrompng($source_filepath); 170 182 } 171 183 else 172 184 { 173 185 die('unsupported file extension'); 186 } 187 188 $rotation = null; 189 if (function_exists('imagerotate')) 190 { 191 $rotation = get_rotation_angle($source_filepath); 174 192 } 175 193 … … 191 209 } 192 210 193 $ratio_width = $source_width / $max_width; 194 $ratio_height = $source_height / $max_height; 195 196 // maximal size exceeded ? 197 if ($ratio_width > 1 or $ratio_height > 1) 198 { 199 if ($ratio_width < $ratio_height) 200 { 201 $destination_width = ceil($source_width / $ratio_height); 202 $destination_height = $max_height; 203 } 204 else 205 { 206 $destination_width = $max_width; 207 $destination_height = ceil($source_height / $ratio_width); 208 } 209 } 210 else 211 $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation); 212 213 // testing on height is useless in theory: if width is unchanged, there 214 // should be no resize, because width/height ratio is not modified. 215 if ($resize_dimensions['width'] == $source_width and $resize_dimensions['height'] == $source_height) 211 216 { 212 217 // the image doesn't need any resize! We just copy it to the destination … … 215 220 } 216 221 217 $destination_image = imagecreatetruecolor($ destination_width, $destination_height);222 $destination_image = imagecreatetruecolor($resize_dimensions['width'], $resize_dimensions['height']); 218 223 219 224 imagecopyresampled( … … 224 229 $x, 225 230 $y, 226 $ destination_width,227 $ destination_height,231 $resize_dimensions['width'], 232 $resize_dimensions['height'], 228 233 $source_width, 229 234 $source_height 230 235 ); 231 232 imagejpeg($destination_image, $destination_filepath, $quality); 236 237 // rotation occurs only on resized photo to avoid useless memory use 238 if (isset($rotation)) 239 { 240 $destination_image = imagerotate($destination_image, $rotation, 0); 241 } 242 243 $extension = strtolower(get_extension($destination_filepath)); 244 if ($extension == 'png') 245 { 246 imagepng($destination_image, $destination_filepath); 247 } 248 else 249 { 250 imagejpeg($destination_image, $destination_filepath, $quality); 251 } 233 252 // freeing memory ressources 234 253 imagedestroy($source_image);
Note: See TracChangeset
for help on using the changeset viewer.