/**
  * Saves the image as destination path name to disc.
  *
  * @param integer $chmod
  * @return sfFilebasePluginImage $destination
  */
 public function save($chmod = 0777)
 {
     if (!$this->destination_resource instanceof Imagick) {
         throw new sfFilebasePluginException('Nothing to save.');
     }
     $this->destination_resource->writeImage($this->destination->getPathname());
     return $this->destination;
 }
コード例 #2
0
 /**
  * Saves the image as destination path name to disc.
  *
  * @param integer $chmod
  * @return sfFilebasePluginImage $destination
  */
 public function save($chmod = 0777)
 {
     if (!is_resource($this->destination_resource)) {
         throw new sfFilebasePluginException('Nothing to save.');
     }
     switch ($this->destination->getMimeType()) {
         case 'image/pjpeg':
         case 'image/jpeg':
             imagejpeg($this->destination_resource, $this->destination->getPathname(), $this->destinationQuality);
             break;
         case 'image/gif':
             imagegif($this->destination_resource, $this->destination->getPathname());
             break;
         case 'image/x-png':
         case 'image/png':
             imagepng($this->destination_resource, $this->destination->getPathname(), round($this->destinationQuality / 10), PNG_ALL_FILTERS);
             break;
     }
     $this->destination->chmod($chmod);
     return $this->destination;
 }
コード例 #3
0
 /**
  * Calculates and returns the properties (width/height) of a thumbail/scaled image.
  *
  * Return value is an array containing calculated width/height and extension.
  *
  * @param sfFilebasePluginImage $fileinfo
  * @param integer $new_width
  * @param integer $new_height
  * @throws sfFilebasePluginException
  * @return array $thumbnail_properties
  */
 public function getScaledImageData(sfFilebasePluginImage $image, array $dimensions)
 {
     $width = 0;
     $height = 0;
     $new_width = null;
     $new_height = null;
     // @todo, den check mach ich auch beim copyResampled. Hier nur gebraucht für filename
     isset($dimensions[0]) && ($dimensions['width'] = $dimensions[0]);
     isset($dimensions[1]) && ($dimensions['height'] = $dimensions[1]);
     isset($dimensions['width']) && (int) $dimensions['width'] > 0 && ($new_width = $dimensions['width']);
     isset($dimensions['height']) && (int) $dimensions['height'] > 0 && ($new_height = $dimensions['height']);
     if ($new_width === null && $new_height === null) {
         throw new sfFilebasePluginException('Dimensions are not properly set.');
     }
     $extension = $image->getExtension();
     list($width, $height) = $image->getImagesize();
     if ($new_height === null) {
         $new_height = round($height * $new_width / $width);
     } elseif ($new_width === null) {
         $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));
 }
コード例 #4
0
 /**
  * Returns a new (child of) sfFilebasePluginFile. It returns an instance,
  * not regarding if the file exists or not. So you can fetch an instance
  * and create the underlying file by sfFilebasePlugin-methods.
  *
  * This method checks if file is a directory, an image
  * a link ... but beware, some attributes can only
  * be calculated if the file really exists in file system.
  *
  * For example, if you want to retrieve a directory that does
  * not exists, an instance of sfFilebasePluginFile is recieved.
  *
  * This behavior is simple and logically correct, but you have to keep it in
  * mind: sfFilebasePlugin cannot forecast what files you want to create. It
  * is probably more confusing for windows users where files are mostly
  * identified by its extension.
  *
  * If the dir exists, you'll get a sfFilebasePluginDirectory.
  *
  * @example $filebase->getFilebaseFile('path/to/directory') retrieves a dir
  *          if it exists in FS, or a sfFilebaseFile if not.
  *
  * @example Creating a new file:
  *          $new_file = $filebase->getFilebaseFile('path/to/new/file.txt');
  *          $filebase->touch($new_file);
  *          In Short: $filebase->touch('path/to/new/file.txt');
  *
  * @example Short way retrieving files:
  *          foreach ($filebase AS $file) ...
  *          with ArrayAccess:
  *          $file = $filebase['/path/to/file'];
  *
  * @todo Implement (sym)link handling.
  * @param string | sfFilebasePluginFile  $filename
  * @return sfFilebasePluginFile
  */
 public function getFilebaseFile($filename)
 {
     if (is_string($filename)) {
         //$filename = sfFilebasePluginUtil::unifySlashes($filename);
         if (strlen($filename) > 0) {
             if (sfFilebasePluginUtil::isAbsolutePathname($filename)) {
                 $filename = new sfFilebasePluginFile($filename, $this->filebase);
             } else {
                 $filename = new sfFilebasePluginFile($this->getPathname() . '/' . $filename, $this->filebase);
             }
         } else {
             $filename = $this;
         }
     }
     if ($filename instanceof sfFilebasePluginFile) {
         // returns only true if file exists, so beware of that
         if ($filename->isLink()) {
             throw new sfFilebasePluginException(sprintf('Error retrieving link %s: Link handling is not yet implemented', $filename->getPathname()));
             //return new sfFilebasePluginLink($filename->getPathname());
         } elseif ($filename->isDir()) {
             $filename = new sfFilebasePluginDirectory($filename->getPathname(), $this->filebase);
         } elseif ($this->filebase->getIsSupportedImage($filename)) {
             $filename = new sfFilebasePluginImage($filename->getPathname(), $this->filebase);
         }
         return $filename;
     }
     throw new sfFilebasePluginException(sprintf('File %s must be of type [string] or instanceof FilebaseFile', $filename));
 }