Changeset 1848

Show
Ignore:
Timestamp:
01/28/2008 02:31:27 PM (12 months ago)
Author:
Shadowhand
Message:

Fixes to Image and the GD Driver:

  • Working on recalculating the width/height, but not complete
  • Image now normalizes the quality setting itself, rather than using the driver
Location:
trunk/system/libraries
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Image.php

    r1844 r1848  
    128128                        throw new Kohana_Exception('image.invalid_height', $height); 
    129129 
     130                if (empty($width) AND empty($height)) 
     131                        throw new Kohana_Exception('image.invalid_dimensions', __FUNCTION__); 
     132 
    130133                if ($master === NULL) 
    131134                { 
     
    171174                if ( ! $this->valid_size('left', $left)) 
    172175                        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__); 
    173179 
    174180                $this->actions['crop'] = array 
     
    243249        public function quality($value) 
    244250        { 
    245                 $this->actions['quality'] = $value; 
     251                $this->actions['quality'] = max(1, min($amount, 100)); 
    246252 
    247253                return $this; 
  • trunk/system/libraries/drivers/Image/GD.php

    r1844 r1848  
    7070                        { 
    7171                                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; 
    7474                                break; 
    7575                                case 'imagegif': 
     
    9696        public function flip($direction) 
    9797        { 
    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; 
    99133        } 
    100134 
     
    105139 
    106140                // Get the current width and height 
    107                 list($width, $height) = $this->properties(); 
     141                $width = imagesx($this->tmp_image); 
     142                $height = imagesy($this->tmp_image); 
    108143 
    109144                // Create the temporary image to copy to 
     
    124159        { 
    125160                // Get the current width and height 
    126                 list($width, $height) = $this->properties(); 
     161                $width = imagesx($this->tmp_image); 
     162                $height = imagesy($this->tmp_image); 
    127163 
    128164                if (substr($properties['width'], -1) === '%') 
     
    138174                } 
    139175 
    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); 
    152192                } 
    153193 
     
    223263         * @param   integer  image width 
    224264         * @param   integer  image height 
    225          * @return  GD resource 
     265         * @return  resource 
    226266         */ 
    227267        protected function imagecreatetransparent($width, $height)