File indexing completed on 2025-03-16 05:29:18

0001 <?php
0002 
0003 namespace Intervention\Image\Commands;
0004 
0005 class IptcCommand extends AbstractCommand
0006 {
0007     /**
0008      * Read Iptc data from the given image
0009      *
0010      * @param  \Intervention\Image\Image $image
0011      * @return boolean
0012      */
0013     public function execute($image)
0014     {
0015         if ( ! function_exists('iptcparse')) {
0016             throw new \Intervention\Image\Exception\NotSupportedException(
0017                 "Reading Iptc data is not supported by this PHP installation."
0018             );
0019         }
0020 
0021         $key = $this->argument(0)->value();
0022 
0023         $info = [];
0024         @getimagesize($image->dirname .'/'. $image->basename, $info);
0025 
0026         $data = [];
0027 
0028         if (array_key_exists('APP13', $info)) {
0029             $iptc = iptcparse($info['APP13']);
0030 
0031             if (is_array($iptc)) {
0032                 $data['DocumentTitle'] = isset($iptc["2#005"][0]) ? $iptc["2#005"][0] : null;
0033                 $data['Urgency'] = isset($iptc["2#010"][0]) ? $iptc["2#010"][0] : null;
0034                 $data['Category'] = isset($iptc["2#015"][0]) ? $iptc["2#015"][0] : null;
0035                 $data['Subcategories'] = isset($iptc["2#020"][0]) ? $iptc["2#020"][0] : null;
0036                 $data['Keywords'] = isset($iptc["2#025"][0]) ? $iptc["2#025"] : null;
0037                 $data['SpecialInstructions'] = isset($iptc["2#040"][0]) ? $iptc["2#040"][0] : null;
0038                 $data['CreationDate'] = isset($iptc["2#055"][0]) ? $iptc["2#055"][0] : null;
0039                 $data['CreationTime'] = isset($iptc["2#060"][0]) ? $iptc["2#060"][0] : null;
0040                 $data['AuthorByline'] = isset($iptc["2#080"][0]) ? $iptc["2#080"][0] : null;
0041                 $data['AuthorTitle'] = isset($iptc["2#085"][0]) ? $iptc["2#085"][0] : null;
0042                 $data['City'] = isset($iptc["2#090"][0]) ? $iptc["2#090"][0] : null;
0043                 $data['SubLocation'] = isset($iptc["2#092"][0]) ? $iptc["2#092"][0] : null;
0044                 $data['State'] = isset($iptc["2#095"][0]) ? $iptc["2#095"][0] : null;
0045                 $data['Country'] = isset($iptc["2#101"][0]) ? $iptc["2#101"][0] : null;
0046                 $data['OTR'] = isset($iptc["2#103"][0]) ? $iptc["2#103"][0] : null;
0047                 $data['Headline'] = isset($iptc["2#105"][0]) ? $iptc["2#105"][0] : null;
0048                 $data['Source'] = isset($iptc["2#110"][0]) ? $iptc["2#110"][0] : null;
0049                 $data['PhotoSource'] = isset($iptc["2#115"][0]) ? $iptc["2#115"][0] : null;
0050                 $data['Copyright'] = isset($iptc["2#116"][0]) ? $iptc["2#116"][0] : null;
0051                 $data['Caption'] = isset($iptc["2#120"][0]) ? $iptc["2#120"][0] : null;
0052                 $data['CaptionWriter'] = isset($iptc["2#122"][0]) ? $iptc["2#122"][0] : null;
0053             }
0054         }
0055 
0056         if (! is_null($key) && is_array($data)) {
0057             $data = array_key_exists($key, $data) ? $data[$key] : false;
0058         }
0059 
0060         $this->setOutput($data);
0061 
0062         return true;
0063     }
0064 }