/**
  * Resizes the source image.
  * 
  * @param array $dimensions
  * @return true if image resizing was successful
  */
 public function resize(array $dimensions)
 {
     if (!$this->source_resource instanceof Imagick || !$this->destination instanceof sfFilebasePluginImage) {
         throw new sfFilebasePluginException('You must set a source and a destination image to resize.');
     }
     $image_data = $this->gfxEditor->getScaledImageData($this->source, $dimensions);
     $width = $image_data['orig_width'];
     $height = $image_data['orig_height'];
     $new_width = $image_data['new_width'];
     $new_height = $image_data['new_height'];
     $mime = $image_data['mime'];
     $this->destination_resource->thumbnailImage($new_width, $new_height);
     return true;
 }
 /**
  * Resizes the source image.
  *
  * Uses some ideas from Adrian Mummey
  * <http://www.mummey.org/2008/11/transparent-gifs-with-php-and-gd/comment-page-1/#comment-264>
  * to preserve transparent color on gifs images.
  *
  * @param array $dimensions
  * @return boolean true if image resizing was successful
  */
 public function resize(array $dimensions)
 {
     if (!is_resource($this->source_resource) || !$this->destination instanceof sfFilebasePluginImage) {
         throw new sfFilebasePluginException('You must set a source and a destination image to resize.');
     }
     $image_data = $this->gfxEditor->getScaledImageData($this->source, $dimensions);
     $width = $image_data['orig_width'];
     $height = $image_data['orig_height'];
     $new_width = $image_data['new_width'];
     $new_height = $image_data['new_height'];
     $mime = $image_data['mime'];
     $this->destination_resource = imagecreatetruecolor($new_width, $new_height);
     if ($this->preserve_transparency && ($mime == 'image/gif' || $mime == 'image/png' || $mime == 'image/x-png')) {
         if ($mime == 'image/gif') {
             imagealphablending($this->destination_resource, false);
             $transparent1 = imagecolorallocatealpha($this->destination_resource, 255, 255, 255, 127);
             imagefilledrectangle($this->destination_resource, 0, 0, $new_width, $new_height, $transparent1);
             imagecolortransparent($this->destination_resource, $transparent1);
         } else {
             imagealphablending($this->destination_resource, false);
         }
         imagesavealpha($this->destination_resource, true);
         switch ($mime) {
             case 'image/png':
             case 'image/x-png':
                 $this->funcs['imagecopyresampled']($this->destination_resource, $this->source_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                 break;
             case 'image/gif':
                 imagecopyresized($this->destination_resource, $this->source_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                 break;
         }
     } else {
         switch ($mime) {
             case 'image/jpeg':
             case 'image/pjpeg':
                 $this->funcs['imagecopyresampled']($this->destination_resource, $this->source_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                 break;
             case 'image/x-png':
             case 'image/png':
                 $this->funcs['imagecopyresampled']($this->destination_resource, $this->source_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                 break;
             case 'image/gif':
                 $this->funcs['imagecopyresampled']($this->destination_resource, $this->source_resource, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                 break;
         }
     }
     return true;
 }