/** * @covers IPTC::Parse */ public function testIPTCParseUTF8() { // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8. $iptcData = "Photoshop 3.08BIM¼Z%G"; $res = IPTC::Parse($iptcData); $this->assertEquals(array('¼'), $res['Keywords']); }
/** * This does the photoshop image resource app13 block * of interest, IPTC-IIM metadata is stored here. * * Mostly just calls doPSIR and doIPTC * * @param string $app13 String containing app13 block from jpeg file */ private function doApp13($app13) { try { $this->iptcType = JpegMetadataExtractor::doPSIR($app13); } catch (MWException $e) { // Error reading the iptc hash information. // This probably means the App13 segment is something other than what we expect. // However, still try to read it, and treat it as if the hash didn't exist. wfDebug("Error parsing iptc data of file: " . $e->getMessage() . "\n"); $this->iptcType = 'iptc-no-hash'; } $iptc = IPTC::parse($app13); $this->addMetadata($iptc, $this->iptcType); }
// process image from base64 $source_before = imagecreatefromstring($imageData_before); $source_after = imagecreatefromstring($imageData_after); $rotate_before = imagerotate($source_before, 0, 0); $imageSave_before = imagejpeg($rotate_before, $target_file_before, 100); // write final EXIF TAG - BEFORE $objIPTC_before = new IPTC($target_file_before); $objIPTC_before->setValue(IPTC_COPYRIGHT_STRING, "A copyright notice"); $objIPTC_before->setValue(IPTC_CAPTION, "A caption descriptions for this picture [BEFORE]."); $objIPTC_before->setValue(IPTC_FIXTURE_IDENTIFIER, "fixture identifier"); $objIPTC_before->setValue(IPTC_CREDIT, "IPTC_CREDIT"); $objIPTC_before->setValue(IPTC_ORIGINATING_PROGRAM, "originating apps"); $objIPTC_before->setValue(IPTC_SOURCE, "IPTC_SOURCE"); // destroy source before pic imagedestroy($source_before); echo "<img src='" . $target_file_before . "' /><br/>"; // process image from base64 $rotate_after = imagerotate($source_after, 0, 0); $imageSave_after = imagejpeg($rotate_after, $target_file_after, 100); // write final EXIF TAG - AFTER $objIPTC_after = new IPTC($target_file_after); $objIPTC_after->setValue(IPTC_COPYRIGHT_STRING, "A copyright notice"); $objIPTC_after->setValue(IPTC_CAPTION, "A caption descriptions for this picture [AFTER]."); $objIPTC_after->setValue(IPTC_FIXTURE_IDENTIFIER, "fixture identifier"); $objIPTC_after->setValue(IPTC_CREDIT, "IPTC_CREDIT"); $objIPTC_after->setValue(IPTC_ORIGINATING_PROGRAM, "originating apps"); $objIPTC_after->setValue(IPTC_SOURCE, "IPTC_SOURCE"); // destroy source before pic imagedestroy($source_after); echo "<img src='" . $target_file_after . "' /><br/>"; }
/** * Get the IPCT date of an image * * @global type $UNC_GALLERY * @param type $file_path * @return boolean */ function unc_ipct_date($file_path) { global $UNC_GALLERY; if ($UNC_GALLERY['debug']) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); } $ipct_obj = new IPTC($file_path); $ipct_date = $ipct_obj->get('created_date'); // '20160220', $ipct_time = $ipct_obj->get('created_time'); // '235834', if (strlen($ipct_date . $ipct_time) != 14) { if ($UNC_GALLERY['debug']) { XMPP_ERROR_trace(__FUNCTION__, "ipct length wrong: {$ipct_date} / {$ipct_time}"); } return false; } $search_pattern = '/(\\d\\d\\d\\d)(\\d\\d)(\\d\\d) (\\d\\d)(\\d\\d)(\\d\\d)/'; $replace_pattern = '$1-$2-$3 $4:$5:$6'; $fixed_date = preg_replace($search_pattern, $replace_pattern, "{$ipct_date} {$ipct_time}"); return $fixed_date; }
function setImageCopyright($file, $copyright) { $obj = new IPTC($file); $obj->setValue(IPTC_COPYRIGHT_STRING, $copyright); }
/** * This does the photoshop image resource app13 block * of interest, IPTC-IIM metadata is stored here. * * Mostly just calls doPSIR and doIPTC * * @param String $app13 String containing app13 block from jpeg file */ private function doApp13($app13) { $this->iptcType = JpegMetadataExtractor::doPSIR($app13); $iptc = IPTC::parse($app13); $this->addMetadata($iptc, $this->iptcType); }