/** * 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; }
/** * 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; }
/** * Creates a Thumbnail named by md5-hash of the image * and its file ending. * * @param mixed sfFilebasePluginImage $fileinfo * @param array $dimensions = array(width, height) */ public function createThumbnail(sfFilebasePluginImage $fileinfo, array $dimensions, $quality, $mime, $preserve_transparency = true) { // Check cache directory if (!$this->filebase->getCacheDirectory()->fileExists()) { throw new sfFilebasePluginException(sprintf('Cache directory %s does not exist.', $this->filebase->getCacheDirectory()->getPathname())); } // Check if original file is writable... if (!$fileinfo->fileExists()) { throw new sfFilebasePluginException(sprintf('File %s does not exist', $fileinfo->getPathname())); } if (!$fileinfo->isReadable()) { throw new sfFilebasePluginException(sprintf('File %s is write protected.', $fileinfo->getPathname())); } if (!$this->filebase->getIsSupportedImage($fileinfo)) { throw new sfFilebasePluginException(sprintf('File %s is not an image.', $fileinfo)); } if (!$fileinfo->isImage()) { throw new sfFilebasePluginException(sprintf('Image format %s is unsupported.', $fileinfo)); } if (!$this->filebase->isInFilebase($fileinfo)) { throw new sfFilebasePluginException(sprintf('FilebaseFile %s does not belong to Filebase %s, cannot be deleted due to security issues', $fileinfo->getPathname(), $this->filebase->getPathname())); } $destination = $this->getThumbnailFileinfo($fileinfo, $dimensions, $mime); return new sfFilebasePluginThumbnail($this->imageCopyResampled($fileinfo, $destination, $dimensions, true, $preserve_transparency), $this->filebase, $fileinfo); }
/** * 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)); }