checkImageMagick(); $this->name = 'Shell'; $this->determineTypes(); parent::__construct(); } /** * Load an image file. * Loads an image file and returns a reference to it. * * @param string $file File to load. * @param string $mime The MIME type of the file. * * @return string Reference to the file in this handler. * * @see ezcImageAnalyzer * * @throws ezcImageHandlerException * @see ezcImageHandlerException::FILE_NOT_EXISTS * @see ezcImageHandlerException::UNKNOWN_TYPE * @see ezcImageHandlerException::FILE_NOT_PROCESSABLE */ public function load( $file, $mime = null ) { $ref = $this->loadCommon( $file, isset( $mime ) ? $mime : null ); // Atomic file operation $fileTmp = tempnam( dirname( $file ), '.' . basename( $file ) ); copy( $file, $fileTmp ); $this->setReferenceData( $ref, $fileTmp, 'resource' ); return $ref; } /** * Save an image file. * Saves a given open file. Can optionally save to a new file name. * * @see ezcImageHandler::load() * * @param string $image File reference created through load(). * @param string $newFile Filename to save the image to. * @param string $mime New MIME type, if differs from initial one. */ public function save( $image, $newFile = null, $mime = null ) { $this->saveCommon( $image, isset( $newFile ) ? $newFile : null, isset( $mime ) ? $mime : null ); $command = $this->binary . ' ' . escapeshellarg( $this->getReferenceData( $image, 'resource' ) ) . ' ' . ( isset( $this->filterOptions[$image] ) ? implode( ' ', $this->filterOptions[$image] ) : '' ) . ' ' . escapeshellarg( $this->tagMap[$this->getReferenceData( $image, 'mime' )] . ':' . $this->getReferenceData( $image, 'resource' ) ); shell_exec( $command ); // Finish atomic file operation copy( $this->getReferenceData( $image, 'resource' ), $this->getReferenceData( $image, 'file' ) ); } /** * Close the file referenced by $image. * Frees the image reference. You should call close() before. * * @see ezcImageHandler::load() * @see ezcImageHandler::save() * @param string $image The image reference. */ public function close( $image ) { unlink( $this->getReferenceData( $image, 'resource' ) ); $this->setReferenceData( $image, false, 'resource' ); $this->closeCommon( $image ); } public function addFilterOption( $reference, $name, $parameter ) { $this->filterOptions[$reference][] = $name . ' ' . escapeshellarg( $parameter ); } /** * Determines the supported input/output types supported by handler. * Set's various attributes to reflect the MIME types this handler is * capeable to process. * */ protected function determineTypes() { $tagMap = array( 'image/x-xpixmap' => 'XPM', 'image/png' => 'PNG', 'image/jpeg' => 'JPEG', 'image/bmp' => 'BMP', 'image/gif' => 'GIF', 'image/x-portable-bitmap' => 'PBM', 'image/tiff' => 'TIFF', 'image/pcx' => 'PCX', 'image/x-pict' => 'PICT', 'image/svg+xml' => 'SVG', 'image/tga' => 'TGA', 'image/vnd.wap.wbmp' => 'WBMP', 'image/x-xbitmap' => 'XBM', 'image/x-xcf-gimp' => 'XCF', 'application/x-photoshop' => 'PSD', 'application/pdf' => 'PDF', 'application/postscript' => 'PS', ); $types = array_keys( $tagMap ); $this->inputTypes = $types; $this->outputTypes = $types; $this->tagMap = $tagMap; } /** * Checks for ImageMagick on the system. * * @return void */ protected function checkImageMagick() { switch ( PHP_OS ) { case 'Linux': case 'Unix': case 'MacOS': $this->binary = 'convert'; break; case 'Windows': $this->binary = 'convert.exe'; break; default: throw new ezcImageHandlerException( 'System <'.PHP_OS.'> not supported by handler <'.$this->name.'>.', ezcImageHandlerException::NOT_AVAILABLE ); break; } $out = shell_exec( $this->binary ); if ( strpos( $out, 'ImageMagick' ) === false ) { throw new ezcImageHandlerException( 'ImageMagick not installed or not available in PATH variable.', ezcImageHandlerException::NOT_AVAILABLE ); } } } ?>