/**
  * 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;
 }
            $new_width = round($width * $new_height / $height);
        }
        return array('orig_width' => $width, 'orig_height' => $height, 'new_width' => $new_width, 'new_height' => $new_height, 'extension' => $extension, 'mime' => sfFilebasePluginUtil::getMimeType($image));
    }
    /**
     * Returns filename for a cached thumbnail, calculated
     * by its properties and dimensions.
     *
     * @param sfFilebasePluginFile $file
     * @param array $thumbnail_properties
     * @return sfFilebasePluginImage $filename
     */
    public function getThumbnailFileinfo(sfFilebasePluginImage $file, $dimensions, $mime)
    {
        $thumbnail_properties = $this->getScaledImageData($file, $dimensions);
        // Wrap in sfFilebasePluginImage because isImage may return false if file does not exist.
        return new sfFilebasePluginThumbnail($this->filebase->getFilebaseFile($this->filebase->getCacheDirectory() . DIRECTORY_SEPARATOR . $this->filebase->getHashForFile($file) . '_' . $thumbnail_properties['new_width'] . '_' . $thumbnail_properties['new_height'] . '.' . (sfFilebasePluginUtil::getExtensionByMime($mime) === null ? $thumbnail_properties['extension'] : sfFilebasePluginUtil::getExtensionByMime($mime))), $this->filebase, $file);
    }
    /**
     * Returns current instance of sfFilebasePlugin.
     * 
     * @return sfFilebasePlugin $filebase
     */
    public function getFilebase()
    {
        return $this->filebase;
    }
}
sfFilebasePluginGfxEditor::registerAdapter('sfFilebasePluginGfxEditorAdapterGD');
sfFilebasePluginGfxEditor::registerAdapter('sfFilebasePluginGfxEditorAdapterIMagick');
 /**
  * Rotates an image file
  *
  * @see sfFilebasePluginGfxEditor::imageRotate()
  * @param sfFilebasePluginImage $image
  * @param float $deg
  * @param $bgcolor: The background color of the rotated image in html-hex
  *                  notation, default #00000
  * @param integer $preserve_transparency: If set to true, transparency of
  *                png or gif images shall be preserved.
  * @return sfFilebasePluginImage $img: the rotated image
  */
 public function rotateImage(sfFilebasePluginImage $image, $deg, $bgcolor = '#000000', $preserve_transparency = true)
 {
     return $this->gfxEditor->imageRotate($image, $deg, $bgcolor, $preserve_transparency);
 }