Changeset 12749 for trunk/admin/include
- Timestamp:
- Dec 16, 2011, 6:00:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/image.class.php
r12581 r12749 98 98 $source_height = $this->image->get_height(); 99 99 100 // Crop image101 if ($crop)102 {103 $x = 0;104 $y = 0;105 106 if ($source_width < $source_height and $follow_orientation)107 {108 list($max_width, $max_height) = array($max_height, $max_width);109 }110 111 $img_ratio = $source_width / $source_height;112 $dest_ratio = $max_width / $max_height;113 114 if($dest_ratio > $img_ratio)115 {116 $destHeight = round($source_width * $max_height / $max_width);117 $y = round(($source_height - $destHeight) / 2 );118 $source_height = $destHeight;119 }120 elseif ($dest_ratio < $img_ratio)121 {122 $destWidth = round($source_height * $max_width / $max_height);123 $x = round(($source_width - $destWidth) / 2 );124 $source_width = $destWidth;125 }126 127 $this->image->crop($source_width, $source_height, $x, $y);128 }129 130 100 $rotation = null; 131 101 if ($automatic_rotation) … … 133 103 $rotation = self::get_rotation_angle($this->source_filepath); 134 104 } 135 $resize_dimensions = self::get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation );105 $resize_dimensions = self::get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation, $crop, $follow_orientation); 136 106 137 107 // testing on height is useless in theory: if width is unchanged, there … … 151 121 $this->image->strip(); 152 122 } 123 124 if (isset($resize_dimensions['crop'])) 125 { 126 $this->image->crop($resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $resize_dimensions['crop']['x'], $resize_dimensions['crop']['y']); 127 } 153 128 154 129 $this->image->resize($resize_dimensions['width'], $resize_dimensions['height']); … … 165 140 } 166 141 167 static function get_resize_dimensions($width, $height, $max_width, $max_height, $rotation=null )142 static function get_resize_dimensions($width, $height, $max_width, $max_height, $rotation=null, $crop=false, $follow_orientation=true) 168 143 { 169 144 $rotate_for_dimensions = false; … … 176 151 { 177 152 list($width, $height) = array($height, $width); 153 } 154 155 if ($crop) 156 { 157 $x = 0; 158 $y = 0; 159 160 if ($width < $height and $follow_orientation) 161 { 162 list($max_width, $max_height) = array($max_height, $max_width); 163 } 164 165 $img_ratio = $width / $height; 166 $dest_ratio = $max_width / $max_height; 167 168 if($dest_ratio > $img_ratio) 169 { 170 $destHeight = round($width * $max_height / $max_width); 171 $y = round(($height - $destHeight) / 2 ); 172 $height = $destHeight; 173 } 174 elseif ($dest_ratio < $img_ratio) 175 { 176 $destWidth = round($height * $max_width / $max_height); 177 $x = round(($width - $destWidth) / 2 ); 178 $width = $destWidth; 179 } 178 180 } 179 181 … … 203 205 } 204 206 205 returnarray(207 $result = array( 206 208 'width' => $destination_width, 207 209 'height'=> $destination_height, 208 210 ); 211 212 if ($crop and ($x or $y)) 213 { 214 $result['crop'] = array( 215 'width' => $width, 216 'height' => $height, 217 'x' => $x, 218 'y' => $y, 219 ); 220 } 221 return $result; 209 222 } 210 223
Note: See TracChangeset
for help on using the changeset viewer.