Changeset 1830

Show
Ignore:
Timestamp:
01/27/2008 08:29:43 PM (12 months ago)
Author:
Shadowhand
Message:

Updated Image_GD driver:

  • Resize, crop, rotate, and sharpen all working
  • Resize does not yet accept percentages
  • Resize does not take the master dim or missing values into account
  • Saving images into different formats is not yet supported
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/drivers/Image_GD.php

    r1829 r1830  
    126126        public function resize($properties) 
    127127        { 
    128                 // Sanitize the resize settings 
    129                 $this->sanitize_geometry($properties); 
    130  
    131128                // Get the current width and height 
    132129                list($width, $height) = $this->properties(); 
    133130 
     131                if (substr($properties['width'], -1) === '%') 
     132                { 
     133                        // Recalculate the percentage to a pixel size 
     134                        $properties['width'] = round($width * (substr($properties['width'], 0, -1) / 100)); 
     135                } 
     136 
     137                if (substr($properties['height'], -1) === '%') 
     138                { 
     139                        // Recalculate the percentage to a pixel size 
     140                        $properties['height'] = round($height * (substr($properties['height'], 0, -1) / 100)); 
     141                } 
     142 
     143                if (empty($properties['width'])) 
     144                { 
     145                        // Determine the width difference and calculate, don't forget $properties['master'] 
     146                } 
     147 
     148                if (empty($properties['height'])) 
     149                { 
     150                        // Determine the width difference and calculate, don't forget $properties['master'] 
     151                } 
     152 
    134153                // Create the temporary image to copy to 
    135154                $img = $this->imagecreatetransparent($properties['width'], $properties['height']); 
     
    149168        public function rotate($amount) 
    150169        { 
     170                // Use current image to rotate 
     171                $img = $this->tmp_image; 
     172 
     173                // Rotate, setting the transparent color 
     174                $img = imagerotate($img, 360 - $amount, $transparent = imagecolorallocatealpha($img, 255, 255, 255, 127), -1); 
     175 
     176                // Fill the background with the transparent "color" 
     177                imagecolortransparent($img, $transparent); 
     178 
     179                // Merge the images 
     180                imagecopymerge($this->tmp_image, $img, 0, 0, 0, 0, imagesx($this->tmp_image), imagesy($this->tmp_image), 100); 
     181 
    151182                // Prevent the alpha from being lost 
    152                 imagealphablending($this->tmp_image, TRUE); 
    153                 imagesavealpha($this->tmp_image, TRUE); 
    154  
    155                 // Rotate, using -1 as the color to preserve transparency 
    156                 $img = imagerotate($this->tmp_image, $amount, -1); 
    157  
    158                 // Destory the current image 
    159                 imagedestroy($this->tmp_image); 
     183                imagealphablending($img, TRUE); 
     184                imagesavealpha($img, TRUE); 
    160185 
    161186                // Swap the new image for the old one 
     
    167192        public function sharpen($amount) 
    168193        { 
    169                 throw new Kohana_Exception('image.unsupported_driver_method', 'sharpen'); 
     194                // Amount should be in the range of 18-10 
     195                $amount = round(abs(-18 + ($amount * 0.08)), 2); 
     196 
     197                // Gaussian blur matrix 
     198                $matrix = array 
     199                ( 
     200                        array(-1, -1, -1), 
     201                        array(-1, $amount, -1), 
     202                        array(-1, -1, -1) 
     203                ); 
     204 
     205                // Perform the sharpen 
     206                imageconvolution($this->tmp_image, $matrix, $amount - 8, 0); 
     207 
     208                return TRUE; 
    170209        } 
    171210