| 1 |
<?php |
| 2 |
|
| 3 |
namespace Intervention\Image\Commands; |
| 4 |
|
| 5 |
use Intervention\Image\Exception\NotSupportedException; |
| 6 |
|
| 7 |
class IptcCommand extends AbstractCommand |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Read Iptc data from the given image |
| 11 |
* |
| 12 |
* @param \Intervention\Image\Image $image |
| 13 |
* @return boolean |
| 14 |
*/ |
| 15 |
public function execute($image) |
| 16 |
{ |
| 17 |
if ( ! function_exists('iptcparse')) { |
| 18 |
throw new NotSupportedException( |
| 19 |
"Reading Iptc data is not supported by this PHP installation." |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
$key = $this->argument(0)->value(); |
| 24 |
|
| 25 |
$info = []; |
| 26 |
@getimagesize($image->dirname .'/'. $image->basename, $info); |
| 27 |
|
| 28 |
$data = []; |
| 29 |
|
| 30 |
if (array_key_exists('APP13', $info)) { |
| 31 |
$iptc = iptcparse($info['APP13']); |
| 32 |
|
| 33 |
if (is_array($iptc)) { |
| 34 |
$data['DocumentTitle'] = isset($iptc["2#005"][0]) ? $iptc["2#005"][0] : null; |
| 35 |
$data['Urgency'] = isset($iptc["2#010"][0]) ? $iptc["2#010"][0] : null; |
| 36 |
$data['Category'] = isset($iptc["2#015"][0]) ? $iptc["2#015"][0] : null; |
| 37 |
$data['Subcategories'] = isset($iptc["2#020"][0]) ? $iptc["2#020"][0] : null; |
| 38 |
$data['Keywords'] = isset($iptc["2#025"][0]) ? $iptc["2#025"] : null; |
| 39 |
$data['ReleaseDate'] = isset($iptc["2#030"][0]) ? $iptc["2#030"][0] : null; |
| 40 |
$data['ReleaseTime'] = isset($iptc["2#035"][0]) ? $iptc["2#035"][0] : null; |
| 41 |
$data['SpecialInstructions'] = isset($iptc["2#040"][0]) ? $iptc["2#040"][0] : null; |
| 42 |
$data['CreationDate'] = isset($iptc["2#055"][0]) ? $iptc["2#055"][0] : null; |
| 43 |
$data['CreationTime'] = isset($iptc["2#060"][0]) ? $iptc["2#060"][0] : null; |
| 44 |
$data['AuthorByline'] = isset($iptc["2#080"][0]) ? $iptc["2#080"][0] : null; |
| 45 |
$data['AuthorTitle'] = isset($iptc["2#085"][0]) ? $iptc["2#085"][0] : null; |
| 46 |
$data['City'] = isset($iptc["2#090"][0]) ? $iptc["2#090"][0] : null; |
| 47 |
$data['SubLocation'] = isset($iptc["2#092"][0]) ? $iptc["2#092"][0] : null; |
| 48 |
$data['State'] = isset($iptc["2#095"][0]) ? $iptc["2#095"][0] : null; |
| 49 |
$data['Country'] = isset($iptc["2#101"][0]) ? $iptc["2#101"][0] : null; |
| 50 |
$data['OTR'] = isset($iptc["2#103"][0]) ? $iptc["2#103"][0] : null; |
| 51 |
$data['Headline'] = isset($iptc["2#105"][0]) ? $iptc["2#105"][0] : null; |
| 52 |
$data['Source'] = isset($iptc["2#110"][0]) ? $iptc["2#110"][0] : null; |
| 53 |
$data['PhotoSource'] = isset($iptc["2#115"][0]) ? $iptc["2#115"][0] : null; |
| 54 |
$data['Copyright'] = isset($iptc["2#116"][0]) ? $iptc["2#116"][0] : null; |
| 55 |
$data['Caption'] = isset($iptc["2#120"][0]) ? $iptc["2#120"][0] : null; |
| 56 |
$data['CaptionWriter'] = isset($iptc["2#122"][0]) ? $iptc["2#122"][0] : null; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
if (! is_null($key) && is_array($data)) { |
| 61 |
$data = array_key_exists($key, $data) ? $data[$key] : false; |
| 62 |
} |
| 63 |
|
| 64 |
$this->setOutput($data); |
| 65 |
|
| 66 |
return true; |
| 67 |
} |
| 68 |
} |
| 69 |
|