Changeset 1848
- Timestamp:
- 01/28/2008 02:31:27 PM (12 months ago)
- Location:
- trunk/system/libraries
- Files:
-
- 2 modified
-
Image.php (modified) (3 diffs)
-
drivers/Image/GD.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/Image.php
r1844 r1848 128 128 throw new Kohana_Exception('image.invalid_height', $height); 129 129 130 if (empty($width) AND empty($height)) 131 throw new Kohana_Exception('image.invalid_dimensions', __FUNCTION__); 132 130 133 if ($master === NULL) 131 134 { … … 171 174 if ( ! $this->valid_size('left', $left)) 172 175 throw new Kohana_Exception('image.invalid_left', $left); 176 177 if (empty($width) AND empty($height)) 178 throw new Kohana_Exception('image.invalid_dimensions', __FUNCTION__); 173 179 174 180 $this->actions['crop'] = array … … 243 249 public function quality($value) 244 250 { 245 $this->actions['quality'] = $value;251 $this->actions['quality'] = max(1, min($amount, 100)); 246 252 247 253 return $this; -
trunk/system/libraries/drivers/Image/GD.php
r1844 r1848 70 70 { 71 71 case 'imagejpeg': 72 // Make sure the quality is in range (defaults to 95%)73 $quality = ($quality === NULL) ? 95 : max(1, min($quality, 100));72 // Default the quality to 95 73 ($quality === NULL) and $quality = 95; 74 74 break; 75 75 case 'imagegif': … … 96 96 public function flip($direction) 97 97 { 98 echo Kohana::debug($direction); 98 // Get the current width and height 99 $width = imagesx($this->tmp_image); 100 $height = imagesy($this->tmp_image); 101 102 // Create the flipped image 103 $flipped = $this->imagecreatetransparent($width, $height); 104 105 if ($direction === Image::HORIZONTAL) 106 { 107 for ($x = 0; $x < $width; $x++) 108 { 109 $status = imagecopy($flipped, $this->tmp_image, $x, 0, $width - $x - 1, 0, 1, $height); 110 } 111 } 112 elseif ($direction === Image::VERTICAL) 113 { 114 for ($y = 0; $y < $height; $y++) 115 { 116 $status = imagecopy($flipped, $this->tmp_image, 0, $y, 0, $height - $y - 1, $width, 1); 117 } 118 } 119 else 120 { 121 // Do nothing 122 return TRUE; 123 } 124 125 if ($status === TRUE) 126 { 127 // Swap the new image for the old one 128 imagedestroy($this->tmp_image); 129 $this->tmp_image = $flipped; 130 } 131 132 return $status; 99 133 } 100 134 … … 105 139 106 140 // Get the current width and height 107 list($width, $height) = $this->properties(); 141 $width = imagesx($this->tmp_image); 142 $height = imagesy($this->tmp_image); 108 143 109 144 // Create the temporary image to copy to … … 124 159 { 125 160 // Get the current width and height 126 list($width, $height) = $this->properties(); 161 $width = imagesx($this->tmp_image); 162 $height = imagesy($this->tmp_image); 127 163 128 164 if (substr($properties['width'], -1) === '%') … … 138 174 } 139 175 140 if (empty($properties['width'])) 141 { 142 /** 143 * @todo Determine the width difference and calculate, don't forget $properties['master']! 144 */ 145 } 146 147 if (empty($properties['height'])) 148 { 149 /** 150 * @todo Determine the height difference and calculate, don't forget $properties['master']! 151 */ 176 if ($properties['master'] === Image::AUTO) 177 { 178 // Change an automatic master dim to the correct type 179 $properties['master'] = ($width > $height) ? Image::WIDTH : Image::HEIGHT; 180 } 181 182 if (empty($properties['height']) OR $properties['master'] === Image::WIDTH) 183 { 184 // Recalculate the height 185 $properties['height'] = round($height * $properties['width'] / $width); 186 } 187 188 if (empty($properties['width']) OR $properties['master'] === Image::HEIGHT) 189 { 190 // Recalculate the width 191 $properties['width'] = round($width * $properties['height'] / $height); 152 192 } 153 193 … … 223 263 * @param integer image width 224 264 * @param integer image height 225 * @return GDresource265 * @return resource 226 266 */ 227 267 protected function imagecreatetransparent($width, $height)
