Apache Zeta Components Manual :: File Source for imagemagick.php

Source for file imagemagick.php

Documentation is available at imagemagick.php

  1. <?php
  2. /**
  3.  * File containing the ezcImageAnalyzerImagemagickHandler class.
  4.  *
  5.  * Licensed to the Apache Software Foundation (ASF) under one
  6.  * or more contributor license agreements.  See the NOTICE file
  7.  * distributed with this work for additional information
  8.  * regarding copyright ownership.  The ASF licenses this file
  9.  * to you under the Apache License, Version 2.0 (the
  10.  * "License"); you may not use this file except in compliance
  11.  * with the License.  You may obtain a copy of the License at
  12.  * 
  13.  *   http://www.apache.org/licenses/LICENSE-2.0
  14.  * 
  15.  * Unless required by applicable law or agreed to in writing,
  16.  * software distributed under the License is distributed on an
  17.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18.  * KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations
  20.  * under the License.
  21.  *
  22.  * @package ImageAnalysis
  23.  * @version //autogentag//
  24.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25.  * @filesource
  26.  */
  27.  
  28. /**
  29.  * Class to retrieve information about a given image file.
  30.  * This is an ezcImageAnalyzerHandler that utilizes ImageMagick to analyze
  31.  * image files.
  32.  *
  33.  * This ezcImageAnalyzerHandler can be configured using the
  34.  * Option 'binary', which must be set to the full path of the ImageMagick
  35.  * "identify" binary. If this option is not submitted to the
  36.  * {@link ezcImageAnalyzerHandler::__construct()} method, the handler will
  37.  * use just the name of the binary ("identify" on Unix, "identify.exe" on
  38.  * Windows).
  39.  *
  40.  * You can provide the options of the ezcImageAnalyzerImagemagickHandler to
  41.  * the {@link ezcImageAnalyzer::setHandlerClasses()}.
  42.  *
  43.  * @package ImageAnalysis
  44.  * @version //autogentag//
  45.  */
  46. {
  47.     /**
  48.      * The ImageMagick binary to utilize.
  49.      *
  50.      * This variable is set during call to
  51.      * {@link ezcImageAnalyzerImagemagickHandler::checkImagemagick()}.
  52.      *
  53.      * @var string 
  54.      */
  55.     protected $binary;
  56.  
  57.     /**
  58.      * Indicates if this handler is available.
  59.      *
  60.      * The first call to
  61.      * {@link ezcImageAnalyzerImagemagickHandler::isAvailable()}
  62.      * determines this variable, which is then used as a cache for the call to
  63.      * {@link ezcImageAnalyzerImagemagickHandler::checkImagemagick()}.
  64.      *
  65.      * @var bool 
  66.      */
  67.     protected $isAvailable;
  68.  
  69.     /**
  70.      * Mapping between ImageMagick identification strings and MIME types.
  71.      *
  72.      * ImageMagick's "identify" command returns an identification string to
  73.      * indicate the file type examined.
  74.      *
  75.      * This map has been handcrafted, because ImageMagick misses the
  76.      * possibility to determine MIME types. It misses some identification
  77.      * strings (mostly for file types which are absolutely rare in use
  78.      * or which ImageMagick is only capable to read or write, but not both.).
  79.      *
  80.      * @var array(string=>string) 
  81.      */
  82.     protected $mimeMap = array(
  83.         'bmp'   => 'image/bmp',
  84.         'bmp2'  => 'image/bmp',
  85.         'bmp3'  => 'image/bmp',
  86.         'cur'   => 'image/x-win-bitmap',
  87.         'dcx'   => 'image/dcx',
  88.         'epdf'  => 'application/pdf',
  89.         'epi'   => 'application/postscript',
  90.         'eps'   => 'application/postscript',
  91.         'eps2'  => 'application/postscript',
  92.         'eps3'  => 'application/postscript',
  93.         'epsf'  => 'application/postscript',
  94.         'epsi'  => 'application/postscript',
  95.         'ept'   => 'application/postscript',
  96.         'ept2'  => 'application/postscript',
  97.         'ept3'  => 'application/postscript',
  98.         'fax'   => 'image/g3fax',
  99.         'fits'  => 'image/x-fits',
  100.         'g3'    => 'image/g3fax',
  101.         'gif'   => 'image/gif',
  102.         'gif87' => 'image/gif',
  103.         'icb'   => 'application/x-icb',
  104.         'ico'   => 'image/x-win-bitmap',
  105.         'icon'  => 'image/x-win-bitmap',
  106.         'jng'   => 'image/jng',
  107.         'jpeg'  => 'image/jpeg',
  108.         'jpg'   => 'image/jpeg',
  109.         'm2v'   => 'video/mpeg2',
  110.         'miff'  => 'application/x-mif',
  111.         'mng'   => 'video/mng',
  112.         'mpeg'  => 'video/mpeg',
  113.         'mpg'   => 'video/mpeg',
  114.         'otb'   => 'image/x-otb',
  115.         'p7'    => 'image/x-xv',
  116.         'palm'  => 'image/x-palm',
  117.         'pbm'   => 'image/pbm',
  118.         'pcd'   => 'image/pcd',
  119.         'pcds'  => 'image/pcd',
  120.         'pcl'   => 'application/pcl',
  121.         'pct'   => 'image/pict',
  122.         'pcx'   => 'image/x-pcx',
  123.         'pdb'   => 'application/vnd.palm',
  124.         'pdf'   => 'application/pdf',
  125.         'pgm'   => 'image/x-pgm',
  126.         'picon' => 'image/xpm',
  127.         'pict'  => 'image/pict',
  128.         'pjpeg' => 'image/pjpeg',
  129.         'png'   => 'image/png',
  130.         'png24' => 'image/png',
  131.         'png32' => 'image/png',
  132.         'png8'  => 'image/png',
  133.         'pnm'   => 'image/pbm',
  134.         'ppm'   => 'image/x-ppm',
  135.         'ps'    => 'application/postscript',
  136.         'psd'   => 'image/x-photoshop',
  137.         'ptif'  => 'image/x-ptiff',
  138.         'ras'   => 'image/ras',
  139.         'sgi'   => 'image/sgi',
  140.         'sun'   => 'image/ras',
  141.         'svg'   => 'image/svg+xml',
  142.         'svgz'  => 'image/svg',
  143.         'text'  => 'text/plain',
  144.         'tga'   => 'image/tga',
  145.         'tif'   => 'image/tiff',
  146.         'tiff'  => 'image/tiff',
  147.         'txt'   => 'text/plain',
  148.         'vda'   => 'image/vda',
  149.         'viff'  => 'image/x-viff',
  150.         'vst'   => 'image/vst',
  151.         'wbmp'  => 'image/vnd.wap.wbmp',
  152.         'xbm'   => 'image/x-xbitmap',
  153.         'xpm'   => 'image/x-xbitmap',
  154.         'xv'    => 'image/x-viff',
  155.         'xwd'   => 'image/xwd',
  156.     );
  157.  
  158.     /**
  159.      * MIME types this handler is capable to read.
  160.      *
  161.      * This array holds an extract of the
  162.      * {@link ezcImageAnalyzerHandler::$mimeMap}, listing all MIME types this
  163.      * handler is capable to analyze. The map is indexed by the MIME type,
  164.      * assigned to boolean true, to speed up hash lookups.
  165.      *
  166.      * @var array(string=>bool) 
  167.      */
  168.     protected $mimeTypes = array(
  169.         'application/pcl' => true,
  170.         'application/pdf' => true,
  171.         'application/postscript' => true,
  172.         'application/vnd.palm' => true,
  173.         'application/x-icb' => true,
  174.         'application/x-mif' => true,
  175.         'image/dcx' => true,
  176.         'image/g3fax' => true,
  177.         'image/gif' => true,
  178.         'image/jng' => true,
  179.         'image/jpeg' => true,
  180.         'image/pbm' => true,
  181.         'image/pcd' => true,
  182.         'image/pict' => true,
  183.         'image/pjpeg' => true,
  184.         'image/png' => true,
  185.         'image/ras' => true,
  186.         'image/sgi' => true,
  187.         'image/svg' => true,
  188.         'image/tga' => true,
  189.         'image/tiff' => true,
  190.         'image/vda' => true,
  191.         'image/vnd.wap.wbmp' => true,
  192.         'image/vst' => true,
  193.         'image/x-fits' => true,
  194.         'image/x-ms-bmp' => true,
  195.         'image/x-otb' => true,
  196.         'image/x-palm' => true,
  197.         'image/x-pcx' => true,
  198.         'image/x-pgm' => true,
  199.         'image/x-photoshop' => true,
  200.         'image/x-ppm' => true,
  201.         'image/x-ptiff' => true,
  202.         'image/x-viff' => true,
  203.         'image/x-win-bitmap' => true,
  204.         'image/x-xbitmap' => true,
  205.         'image/x-xv' => true,
  206.         'image/xpm' => true,
  207.         'image/xwd' => true,
  208.         'text/plain' => true,
  209.         'video/mng' => true,
  210.         'video/mpeg' => true,
  211.         'video/mpeg2' => true,
  212.     );
  213.  
  214.     /**
  215.      * Analyzes the image type.
  216.      * This method analyzes image data to determine the MIME type. This method
  217.      * returns the MIME type of the file to analyze in lowercase letters (e.g.
  218.      * "image/jpeg") or false, if the images MIME type could not be determined.
  219.      *
  220.      * For a list of image types this handler will be able to analyze, see
  221.      * {@link ezcImageAnalyzerImagemagickHandler}.
  222.      *
  223.      * @param string $file The file to analyze.
  224.      * @return string|boolThe MIME type if analyzation suceeded or false.
  225.      */
  226.     public function analyzeType$file )
  227.     {
  228.         $format ezcBaseFeatures::os(=== 'Windows' '"%m|"' escapeshellarg'%m|' ) );
  229.         $parameters '-format ' $format ' ' escapeshellarg$file );
  230.         $res ezcImageAnalyzerImagemagickHandler::runCommand$parameters$outputString$errorString );
  231.         if $res !== || $errorString !== '' )
  232.         {
  233.             return false;
  234.         }
  235.         $identifiers explode'|'strtolower$outputString ));
  236.         if !isset$this->mimeMap[$identifiers[0]] ) )
  237.         {
  238.             return false;
  239.         }
  240.         return $this->mimeMap[$identifiers[0]];
  241.     }
  242.  
  243.     /**
  244.      * Analyze the image for detailed information.
  245.      *
  246.      * This may return various information about the image, depending on it's
  247.      * type. All information is collected in the struct
  248.      * {@link ezcImageAnalyzerData}. At least the
  249.      * {@link ezcImageAnalyzerData::$mime} attribute is always available, if the
  250.      * image type can be analyzed at all. Additionally this handler will always
  251.      * set the {@link ezcImageAnalyzerData::$width},
  252.      * {@link ezcImageAnalyzerData::$height} and
  253.      * {@link ezcImageAnalyzerData::$size} attributes. For detailes information
  254.      * on the additional data returned, see {@link ezcImageAnalyzerImagemagickHandler}.
  255.      *
  256.      * @todo Why does ImageMagick return the wrong file size on TIFF with comments?
  257.      * @todo Check for translucent transparency.
  258.      *
  259.      * @throws ezcImageAnalyzerFileNotProcessableException
  260.      *          If image file can not be processed.
  261.      * @param string $file The file to analyze.
  262.      * @return ezcImageAnalyzerData 
  263.      */
  264.     public function analyzeImage$file )
  265.     {
  266.         // Example strings returned here:
  267.         // JPEG (Exif without comment):
  268.         // string(45) "[JPEG|76383|399|600|8|59428|DirectClassRGB|]*"
  269.         // --------------------------------
  270.         // TIFF (Exif with comment):
  271.         // string(79) "[TIFF|108125|399|600|8|113524|DirectClassRGB|A simple comment in a TIFF file.]*"
  272.         // --------------------------------
  273.         // PNG:
  274.         // string(46) "[PNG|5420|160|120|8|254|DirectClassRGBMatte|]*"
  275.         // --------------------------------
  276.         // GIF (Animated):
  277.         // string(168) "[GIF|4100|80|50|8|38|PseudoClassRGB|]*[GIF|4100|80|50|8|21|PseudoClassRGB|]*[GIF|4100|80|50|8|17|PseudoClassRGB|Copyright 1996 DeMorgan Industries Corp.
  278.         // 
  279.         // Animated Cog]*"
  280.         // --------------------------------
  281.  
  282.         $formatString ezcBaseFeatures::os(=== 'Windows' '"[%m|%b|%w|%h|%k|%r|%c]*"' escapeshellarg'[%m|%b|%w|%h|%k|%r|%c]*' ) );
  283.         $command '-format ' $formatString ' ' escapeshellarg$file );
  284.  
  285.         // Execute ImageMagick
  286.         $return $this->runCommand$command$outputString$errorString );
  287.         if $return !== || $errorString !== '' )
  288.         {
  289.             throw new ezcImageAnalyzerFileNotProcessableException$file"ImageMagick error: '{$errorString}'.);
  290.         }
  291.  
  292.         $dataStruct new ezcImageAnalyzerData();
  293.  
  294.         $rawDataArr explode'*'$outputString );
  295.         if sizeof$rawDataArr === )
  296.         {
  297.             throw new ezcImageAnalyzerFileNotProcessableException$file"ImageMagick did not return correct formated string." );
  298.         }
  299.  
  300.         // Unset last (empty) element
  301.         unset$rawDataArr[count$rawDataArr 1);
  302.  
  303.         if sizeof$rawDataArr )
  304.         {
  305.             $dataStruct->isAnimated true;
  306.         }
  307.         foreach $rawDataArr as $id => $rawData )
  308.         {
  309.             $parsedData explode'|'substr$rawData1-) );
  310.             $dataStruct->mime     $this->mimeMap[strtolower$parsedData[0)];
  311.  
  312.             $dataStruct->size     filesize$file );
  313.  
  314.             $dataStruct->width    max(int) $parsedData[2]$dataStruct->width );
  315.             $dataStruct->height   max(int) $parsedData[3]$dataStruct->height );
  316.  
  317.             $dataStruct->isColor  $parsedData[4true false;
  318.  
  319.             $dataStruct->transparencyType self::TRANSPARENCY_OPAQUE;
  320.             if strpos$parsedData[5]'RGBMatte' !== FALSE )
  321.             {
  322.                 $dataStruct->transparencyType self::TRANSPARENCY_TRANSPARENT;
  323.             }
  324.  
  325.             if $parsedData[6!== '' )
  326.             {
  327.                 if $dataStruct->isAnimated && $id )
  328.                 {
  329.                     $dataStruct->commentList[$parsedData[6];
  330.                 }
  331.                 else
  332.                 {
  333.                     $dataStruct->comment $parsedData[6];
  334.                     $dataStruct->commentList array$parsedData[6);
  335.                 }
  336.             }
  337.  
  338.             if $dataStruct->mime === 'image/jpeg' || $dataStruct->mime === 'image/tiff' )
  339.             {
  340.                 $this->analyzeExif$dataStruct$file );
  341.             }
  342.         }
  343.         return $dataStruct;
  344.     }
  345.  
  346.     /**
  347.      * Analyze Exif data contained in JPEG and TIFF images.
  348.      *
  349.      * This method analyzes the Exif data contained in JPEG and TIFF images,
  350.      * using ImageMagick's "identify" binary.
  351.      *
  352.      * This method tries to provide the EXIF data in a format as close as
  353.      * possible to the format returned by ext/EXIF {@link http://php.net/exif}.
  354.      *
  355.      * @param ezcImageAnalyzerData $data The data object to fill.
  356.      * @param string $file               The file to analyze.
  357.      */
  358.     protected function analyzeExifezcImageAnalyzerData $data$file )
  359.     {
  360.         $tagMap array(
  361.             "IFD0" => array(
  362.                 "ImageDescription",
  363.                 "Make",
  364.                 "Model",
  365.                 "Orientation",
  366.                 "XResolution",
  367.                 "YResolution",
  368.                 "ResolutionUnit",
  369.                 "Software",
  370.                 "DateTime",
  371.                 "YCbCrPositioning",
  372.                 "Exif_IFD_Pointer",
  373.                 "Copyright",
  374.                 "UserComment",
  375.             ),
  376.  
  377.             "EXIF" => array(
  378.                 "ExposureTime",
  379.                 "FNumber",
  380.                 "ExposureProgram",
  381.                 "ISOSpeedRatings",
  382.                 "ExifVersion",
  383.                 "DateTimeOriginal",
  384.                 "DateTimeDigitized",
  385.                 "ComponentsConfiguration",
  386.                 "BrightnessValue",
  387.                 "ExposureBiasValue",
  388.                 "MaxApertureValue",
  389.                 "MeteringMode",
  390.                 "LightSource",
  391.                 "Flash",
  392.                 "FocalLength",
  393.             // ImageMagick does not grab this correct, therefore not supported
  394.             //  "SubjectLocation",
  395.                 "MakerNote",
  396.                 "UserComment",
  397.                 "FlashPixVersion",
  398.                 "ColorSpace",
  399.                 "ExifImageWidth",
  400.                 "ExifImageLength",
  401.                 "InteroperabilityOffset",
  402.                 "FileSource",
  403.                 "SceneType",
  404.                 "CustomRendered",
  405.                 "ExposureMode",
  406.                 "WhiteBalance",
  407.                 "DigitalZoomRatio",
  408.                 "FocalLengthIn35mmFilm",
  409.                 "SceneCaptureType",
  410.                 "GainControl",
  411.                 "Contrast",
  412.                 "Saturation",
  413.                 "Sharpness",
  414.                 "SubjectDistanceRange",
  415.             ),
  416.             "INTEROP" => array(
  417.                 "InterOperabilityIndex",
  418.                 "InterOperabilityVersion"
  419.             )
  420.         );
  421.  
  422.         // Retreive exif data
  423.         $command '-format ' escapeshellarg"%[EXIF:*]"  ' ' escapeshellarg$file );
  424.         $return $this->runCommand$command$outputString$errorStringfalse );
  425.         if $return !== || $errorString !== '' )
  426.         {
  427.             throw new ezcImageAnalyzerFileNotProcessableException$file"ImageMagick error: '{$errorString}'.);
  428.         }
  429.  
  430.         // The following is done in 2 steps to ensure the same array order as ext/exif provides.
  431.  
  432.         // Pre-process data
  433.         $rawData explode"\n"$outputString );
  434.         $dataArr array();
  435.         foreach $rawData as $dataString )
  436.         {
  437.             $dataParts explode"="$dataString);
  438.             if sizeof$dataParts === )
  439.             {
  440.                 $dataArr[$dataParts[0]] substr$dataParts[1]-1=== "." substr$dataParts[1]0-$dataParts[1];
  441.             }
  442.         }
  443.         // Some post-processing is needed because ext/exif has some different tag names
  444.         if isset$dataArr["ExifOffset") )
  445.         {
  446.             $dataArr["Exif_IFD_Pointer"=  $dataArr["ExifOffset"];
  447.         }
  448.         if isset$dataArr["InteroperabilityIndex") )
  449.         {
  450.             $dataArr["InterOperabilityIndex"$dataArr["InteroperabilityIndex"];
  451.         }
  452.         if isset$dataArr["InteroperabilityVersion") )
  453.         {
  454.             $dataArr["InterOperabilityVersion"$dataArr["InteroperabilityVersion"];
  455.         }
  456.         if isset$dataArr["Artist") )
  457.         {
  458.             $dataArr["Author"$dataArr["Artist"];
  459.         }
  460.  
  461.         // Assign data to tags
  462.         $exifArr array();
  463.         foreach $tagMap as $section => $tags )
  464.         {
  465.             foreach $tags as $tag )
  466.             {
  467.                 if isset$dataArr[$tag) )
  468.                 {
  469.                     // Correct types
  470.                     switch true )
  471.                     {
  472.                         case ctype_digit$dataArr[$tag&& stripos$tag"version" === false ):
  473.                             $exifArr[$section][$tag= (int)$dataArr[$tag];
  474.                             break;
  475.                         case is_numeric$dataArr[$tag&& stripos$tag"version" === false ):
  476.                             $exifArr[$section][$tag= (float)$dataArr[$tag];
  477.                             break;
  478.                         default:
  479.                             $exifArr[$section][$tag$dataArr[$tag];
  480.                             break;
  481.                     }
  482.                 }
  483.             }
  484.         }
  485.  
  486.         // Retreive additional data for computation
  487.         $imageData getimagesize$file );
  488.  
  489.         $colorCount 0;
  490.         $command '-format ' escapeshellarg'%k' ' ' escapeshellarg$file );
  491.         $return $this->runCommand$command$colorCount$errorString );
  492.         if $return !== || $errorString !== '' )
  493.         {
  494.             throw new ezcImageAnalyzerFileNotProcessableException$file"ImageMagick error: '{$errorString}'.);
  495.         }
  496.  
  497.         // Compute additional section ext/EXIF provides
  498.         $additionsArr array();
  499.         $addtionsArr["FILE"]["FileName"]               =  basename$file );
  500.         $addtionsArr["FILE"]["FileDateTime"]           =  filemtime$file );
  501.         $addtionsArr["FILE"]["FileSize"]               =  filesize$file );
  502.         $addtionsArr["FILE"]["FileType"]               =  $imageData[2];
  503.         $addtionsArr["FILE"]["MimeType"]               =  $data->mime;
  504.         $addtionsArr["FILE"]["SectionsFound"]          =
  505.                 isset$exifArr["EXIF"|| isset$exifArr["IFD0""ANY_TAG, " "" )
  506.                 . implode", "array_keys$exifArr ) );
  507.  
  508.         $addtionsArr["COMPUTED"]["html"]               =  "width=\"{$data->width}\" height=\"{$data->height}\"";
  509.         $addtionsArr["COMPUTED"]["Height"]             =  $data->height;
  510.         $addtionsArr["COMPUTED"]["Width"]              =  $data->width;
  511.         $addtionsArr["COMPUTED"]["IsColor"]            =  $colorCount 1;
  512.  
  513.         // @todo Implement if possible!
  514.         // $addtionsArr["COMPUTED"]["ByteOrderMotorola"]  =  null;
  515.  
  516.         $fNumberParts = isset$exifArr["EXIF"]["FNumber"explode"/"$exifArr["EXIF"]["FNumber"null;
  517.         if sizeof$fNumberParts === )
  518.         {
  519.             $addtionsArr["COMPUTED"]["ApertureFNumber"sprintf"f/%.1f"$fNumberParts[0$fNumberParts[1);
  520.         }
  521.         // ImageMagick resturns "..." for not set comments
  522.         if isset$exifArr["EXIF"]["UserComment") )
  523.         {
  524.             $addtionsArr["COMPUTED"]["UserComment"]    =  preg_match"/^\.*$/"$exifArr["EXIF"]["UserComment"=== false $exifArr["EXIF"]["UserComment"null;
  525.             // @todo Maybe we can determine that somehow?
  526.             // $addtionsArr["COMPUTED"]["UserCommentEncoding"] =  "UNDEFINED";
  527.         }
  528.  
  529.         // Not available through ImageMagick
  530.         // $addtionsArr["COMPUTED"]["Thumbnail.FileType"]  =  null
  531.         // $addtionsArr["COMPUTED"]["Thumbnail.MimeType"]  =  null
  532.  
  533.         // Merge arrays (done here, to have consistent key order)
  534.         $data->exif array_merge$addtionsArr$exifArr );
  535.     }
  536.  
  537.     /**
  538.      * Returns if the handler can analyze a given MIME type.
  539.      *
  540.      * This method returns if the driver is capable of analyzing a given MIME
  541.      * type. This method should be called before trying to actually analyze an
  542.      * image using the drivers {@link ezcImageAnalyzerHandler::analyzeImage()}
  543.      * method.
  544.      *
  545.      * @param string $mime The MIME type to check for.
  546.      * @return bool True if the handler is able to analyze the MIME type.
  547.      */
  548.     public function canAnalyze$mime )
  549.     {
  550.         return isset$this->mimeTypes[strtolower$mime ));
  551.     }
  552.  
  553.     /**
  554.      * Checks wether the GD handler is available on the system.
  555.      *
  556.      * Returns if PHP's {@link getimagesize()} function is available.
  557.      *
  558.      * @return bool True is the handler is available.
  559.      */
  560.     public function isAvailable()
  561.     {
  562.         if !isset$this->isAvailable ) )
  563.         {
  564.             $this->isAvailable = $this->checkImagemagick();
  565.         }
  566.         return $this->isAvailable;
  567.     }
  568.  
  569.     /**
  570.      * Checks the availability of ImageMagick on the system.
  571.      * 
  572.      * @return bool 
  573.      */
  574.     protected function checkImagemagick()
  575.     {
  576.         if !isset$this->options['binary') )
  577.         {
  578.             $this->binary = ezcBaseFeatures::getImageIdentifyExecutable();
  579.         }
  580.         else if file_exists$this->options['binary') )
  581.         {
  582.             $this->binary = $this->options['binary'];
  583.         }
  584.  
  585.         return $this->binary !== null );
  586.     }
  587.  
  588.     /**
  589.      * Run the binary registered in ezcImageAnalyzerImagemagickHandler::$binary.
  590.      *
  591.      * This method executes the ImageMagick binary using the applied parameter
  592.      * string. It returns the return value of the command. The output printed
  593.      * to STDOUT and ERROUT is available through the $stdOut and $errOut
  594.      * parameters.
  595.      *
  596.      * @param string $parameters    The parameters for the binary to execute.
  597.      * @param string $stdOut        The standard output.
  598.      * @param string $errOut        The error output.
  599.      * @param bool   $stripNewlines Wether to strip the newlines from STDOUT.
  600.      * @return int The return value of the command (0 on success).
  601.      */
  602.     protected function runCommand$parameters&$stdOut&$errOut$stripNewlines true )
  603.     {
  604.         $command ezcBaseFeatures::os(=== 'Windows' $this->binary : escapeshellcmd$this->binary ) )
  605.             . $parameters !== '' ?  ' ' $parameters '' );
  606.         // Prepare to run ImageMagick command
  607.         $descriptors array(
  608.             array'pipe''r' ),
  609.             array'pipe''w' ),
  610.             array'pipe''w' ),
  611.         );
  612.  
  613.         // Open ImageMagick process
  614.         $process proc_open$command$descriptors$pipes );
  615.  
  616.         // Close STDIN pipe
  617.         fclose$pipes[0);
  618.  
  619.         // Read STDOUT
  620.         $stdOut '';
  621.         do
  622.         {
  623.             $stdOut .= $stripNewlines === true rtrimfgets$pipes[1]1024)"\n" fgets$pipes[1]1024 );
  624.         while !feof$pipes[1) );
  625.  
  626.         // Read STDERR
  627.         $errOut '';
  628.         do
  629.         {
  630.             $errOut .= rtrimfgets$pipes[2]1024)"\n" );
  631.         while !feof$pipes[2) );
  632.  
  633.         // Wait for process to terminate and store return value
  634.         return proc_close$process );
  635.     }
  636. }
  637. ?>
Documentation generated by phpDocumentor 1.4.3