diff --git a/src/Format/JPEG.php b/src/Format/JPEG.php index d58f68d..0ca2867 100644 --- a/src/Format/JPEG.php +++ b/src/Format/JPEG.php @@ -1,10 +1,11 @@ @@ -66,6 +67,7 @@ private function getSegmentsByName($name) public function setXmp(Xmp $xmp) { $this->xmp = $xmp; + return $this; } @@ -101,7 +103,7 @@ public function save($filename = null) $handle = @fopen($filename, 'wb'); // Check if the file opened successfully - if (!$handle) { + if (! $handle) { throw new \Exception(sprintf('Could not open file %s', $filename)); } @@ -124,8 +126,8 @@ private function write($handle) // write each segment foreach ($this->segments as $segment) { - $segmentContent = sprintf("\xFF%c", $segment->getType()); // marker - $segmentContent .= pack("n", strlen($segment->getData()) + 2); // size + $segmentContent = sprintf("\xFF%c", $segment->getType()); // marker + $segmentContent .= pack('n', strlen($segment->getData()) + 2); // size $segmentContent .= $segment->getData(); fwrite($handle, $segmentContent); @@ -180,6 +182,7 @@ public static function fromString($string) public static function fromImagick(\Imagick $imagick) { $imagick->setImageFormat('jpg'); + return self::fromString($imagick->getImageBlob()); } @@ -215,7 +218,7 @@ public static function fromStream($fileHandle, $filename = null) $imageData = null; // Cycle through the file until, either an EOI (End of image) marker is hit or end of file is hit - while (($data[1] != "\xD9") && (!feof($fileHandle))) { + while (($data[1] != "\xD9") && (! feof($fileHandle))) { // Found a segment to look at. // Check that the segment marker is not a restart marker, restart markers don't have size or data if ((ord($data[1]) < 0xD0) || (ord($data[1]) > 0xD7)) { @@ -234,7 +237,7 @@ public static function fromStream($fileHandle, $filename = null) $compressedData = ''; do { $compressedData .= fread($fileHandle, 1048576); - } while (!feof($fileHandle)); + } while (! feof($fileHandle)); // Strip off EOI and anything after $eoiPos = strpos($compressedData, "\xFF\xD9"); @@ -253,7 +256,6 @@ public static function fromStream($fileHandle, $filename = null) } return new self($imageData, $segments, $filename); - } finally { fclose($fileHandle); } @@ -273,7 +275,7 @@ public static function fromFile($filename) { $fileHandle = @fopen($filename, 'rb'); - if (!$fileHandle) { + if (! $fileHandle) { throw new \Exception(sprintf('Could not open file %s', $filename)); } @@ -287,18 +289,19 @@ private function insertXmpSegment() { $xmp = $this->getXmp(); - if (!$xmp) { + if (! $xmp) { return; } $renderSegment = function (Xmp $xmp) { - return "http://ns.adobe.com/xap/1.0/\x00" . $xmp->getString(); + return "http://ns.adobe.com/xap/1.0/\x00".$xmp->getString(); }; foreach ($this->getSegmentsByName('APP1') as $segment) { // And if it has the Adobe XMP/RDF label (http://ns.adobe.com/xap/1.0/\x00) , if (strncmp($segment->getData(), "http://ns.adobe.com/xap/1.0/\x00", 29) == 0) { $segment->setData($renderSegment($xmp)); + return; } } @@ -322,7 +325,7 @@ private function insertXmpSegment() */ public function getXmp() { - if (!$this->xmp) { + if (! $this->xmp) { $possible = $this->getSegmentsByName('APP1'); $xmpData = null; diff --git a/src/Format/JPEG/Segment.php b/src/Format/JPEG/Segment.php index 772d64c..ace6613 100644 --- a/src/Format/JPEG/Segment.php +++ b/src/Format/JPEG/Segment.php @@ -1,4 +1,5 @@ "SOF0", 0xC1 => "SOF1", 0xC2 => "SOF2", 0xC3 => "SOF4", - 0xC5 => "SOF5", 0xC6 => "SOF6", 0xC7 => "SOF7", 0xC8 => "JPG", - 0xC9 => "SOF9", 0xCA => "SOF10", 0xCB => "SOF11", 0xCD => "SOF13", - 0xCE => "SOF14", 0xCF => "SOF15", - 0xC4 => "DHT", 0xCC => "DAC", + 0xC0 => 'SOF0', 0xC1 => 'SOF1', 0xC2 => 'SOF2', 0xC3 => 'SOF4', + 0xC5 => 'SOF5', 0xC6 => 'SOF6', 0xC7 => 'SOF7', 0xC8 => 'JPG', + 0xC9 => 'SOF9', 0xCA => 'SOF10', 0xCB => 'SOF11', 0xCD => 'SOF13', + 0xCE => 'SOF14', 0xCF => 'SOF15', + 0xC4 => 'DHT', 0xCC => 'DAC', - 0xD0 => "RST0", 0xD1 => "RST1", 0xD2 => "RST2", 0xD3 => "RST3", - 0xD4 => "RST4", 0xD5 => "RST5", 0xD6 => "RST6", 0xD7 => "RST7", + 0xD0 => 'RST0', 0xD1 => 'RST1', 0xD2 => 'RST2', 0xD3 => 'RST3', + 0xD4 => 'RST4', 0xD5 => 'RST5', 0xD6 => 'RST6', 0xD7 => 'RST7', - 0xD8 => "SOI", 0xD9 => "EOI", 0xDA => "SOS", 0xDB => "DQT", - 0xDC => "DNL", 0xDD => "DRI", 0xDE => "DHP", 0xDF => "EXP", + 0xD8 => 'SOI', 0xD9 => 'EOI', 0xDA => 'SOS', 0xDB => 'DQT', + 0xDC => 'DNL', 0xDD => 'DRI', 0xDE => 'DHP', 0xDF => 'EXP', - 0xE0 => "APP0", 0xE1 => "APP1", 0xE2 => "APP2", 0xE3 => "APP3", - 0xE4 => "APP4", 0xE5 => "APP5", 0xE6 => "APP6", 0xE7 => "APP7", - 0xE8 => "APP8", 0xE9 => "APP9", 0xEA => "APP10", 0xEB => "APP11", - 0xEC => "APP12", 0xED => "APP13", 0xEE => "APP14", 0xEF => "APP15", + 0xE0 => 'APP0', 0xE1 => 'APP1', 0xE2 => 'APP2', 0xE3 => 'APP3', + 0xE4 => 'APP4', 0xE5 => 'APP5', 0xE6 => 'APP6', 0xE7 => 'APP7', + 0xE8 => 'APP8', 0xE9 => 'APP9', 0xEA => 'APP10', 0xEB => 'APP11', + 0xEC => 'APP12', 0xED => 'APP13', 0xEE => 'APP14', 0xEF => 'APP15', - 0xF0 => "JPG0", 0xF1 => "JPG1", 0xF2 => "JPG2", 0xF3 => "JPG3", - 0xF4 => "JPG4", 0xF5 => "JPG5", 0xF6 => "JPG6", 0xF7 => "JPG7", - 0xF8 => "JPG8", 0xF9 => "JPG9", 0xFA => "JPG10", 0xFB => "JPG11", - 0xFC => "JPG12", 0xFD => "JPG13", + 0xF0 => 'JPG0', 0xF1 => 'JPG1', 0xF2 => 'JPG2', 0xF3 => 'JPG3', + 0xF4 => 'JPG4', 0xF5 => 'JPG5', 0xF6 => 'JPG6', 0xF7 => 'JPG7', + 0xF8 => 'JPG8', 0xF9 => 'JPG9', 0xFA => 'JPG10', 0xFB => 'JPG11', + 0xFC => 'JPG12', 0xFD => 'JPG13', - 0xFE => "COM", 0x01 => "TEM", 0x02 => "RES" + 0xFE => 'COM', 0x01 => 'TEM', 0x02 => 'RES', ]; private static $segmentDescriptions = [ - 0xC0 => "Start Of Frame (SOF) Huffman - Baseline DCT", - 0xC1 => "Start Of Frame (SOF) Huffman - Extended sequential DCT", - 0xC2 => "Start Of Frame Huffman - Progressive DCT (SOF2)", - 0xC3 => "Start Of Frame Huffman - Spatial (sequential) lossless (SOF3)", - 0xC5 => "Start Of Frame Huffman - Differential sequential DCT (SOF5)", - 0xC6 => "Start Of Frame Huffman - Differential progressive DCT (SOF6)", - 0xC7 => "Start Of Frame Huffman - Differential spatial (SOF7)", - 0xC8 => "Start Of Frame Arithmetic - Reserved for JPEG extensions (JPG)", - 0xC9 => "Start Of Frame Arithmetic - Extended sequential DCT (SOF9)", - 0xCA => "Start Of Frame Arithmetic - Progressive DCT (SOF10)", - 0xCB => "Start Of Frame Arithmetic - Spatial (sequential) lossless (SOF11)", - 0xCD => "Start Of Frame Arithmetic - Differential sequential DCT (SOF13)", - 0xCE => "Start Of Frame Arithmetic - Differential progressive DCT (SOF14)", - 0xCF => "Start Of Frame Arithmetic - Differential spatial (SOF15)", - 0xC4 => "Define Huffman Table(s) (DHT)", - 0xCC => "Define Arithmetic coding conditioning(s) (DAC)", - - 0xD0 => "Restart with modulo 8 count 0 (RST0)", - 0xD1 => "Restart with modulo 8 count 1 (RST1)", - 0xD2 => "Restart with modulo 8 count 2 (RST2)", - 0xD3 => "Restart with modulo 8 count 3 (RST3)", - 0xD4 => "Restart with modulo 8 count 4 (RST4)", - 0xD5 => "Restart with modulo 8 count 5 (RST5)", - 0xD6 => "Restart with modulo 8 count 6 (RST6)", - 0xD7 => "Restart with modulo 8 count 7 (RST7)", - - 0xD8 => "Start of Image (SOI)", - 0xD9 => "End of Image (EOI)", - 0xDA => "Start of Scan (SOS)", - 0xDB => "Define quantization Table(s) (DQT)", - 0xDC => "Define Number of Lines (DNL)", - 0xDD => "Define Restart Interval (DRI)", - 0xDE => "Define Hierarchical progression (DHP)", - 0xDF => "Expand Reference Component(s) (EXP)", - - 0xE0 => "Application Field 0 (APP0) - usually JFIF or JFXX", - 0xE1 => "Application Field 1 (APP1) - usually EXIF or XMP/RDF", - 0xE2 => "Application Field 2 (APP2) - usually Flashpix", - 0xE3 => "Application Field 3 (APP3)", - 0xE4 => "Application Field 4 (APP4)", - 0xE5 => "Application Field 5 (APP5)", - 0xE6 => "Application Field 6 (APP6)", - 0xE7 => "Application Field 7 (APP7)", - - 0xE8 => "Application Field 8 (APP8)", - 0xE9 => "Application Field 9 (APP9)", - 0xEA => "Application Field 10 (APP10)", - 0xEB => "Application Field 11 (APP11)", - 0xEC => "Application Field 12 (APP12) - usually [picture info]", - 0xED => "Application Field 13 (APP13) - usually photoshop IRB / IPTC", - 0xEE => "Application Field 14 (APP14)", - 0xEF => "Application Field 15 (APP15)", - - 0xF0 => "Reserved for JPEG extensions (JPG0)", - 0xF1 => "Reserved for JPEG extensions (JPG1)", - 0xF2 => "Reserved for JPEG extensions (JPG2)", - 0xF3 => "Reserved for JPEG extensions (JPG3)", - 0xF4 => "Reserved for JPEG extensions (JPG4)", - 0xF5 => "Reserved for JPEG extensions (JPG5)", - 0xF6 => "Reserved for JPEG extensions (JPG6)", - 0xF7 => "Reserved for JPEG extensions (JPG7)", - 0xF8 => "Reserved for JPEG extensions (JPG8)", - 0xF9 => "Reserved for JPEG extensions (JPG9)", - 0xFA => "Reserved for JPEG extensions (JPG10)", - 0xFB => "Reserved for JPEG extensions (JPG11)", - 0xFC => "Reserved for JPEG extensions (JPG12)", - 0xFD => "Reserved for JPEG extensions (JPG13)", - - 0xFE => "Comment (COM)", - 0x01 => "For temp private use arith code (TEM)", - 0x02 => "Reserved (RES)" + 0xC0 => 'Start Of Frame (SOF) Huffman - Baseline DCT', + 0xC1 => 'Start Of Frame (SOF) Huffman - Extended sequential DCT', + 0xC2 => 'Start Of Frame Huffman - Progressive DCT (SOF2)', + 0xC3 => 'Start Of Frame Huffman - Spatial (sequential) lossless (SOF3)', + 0xC5 => 'Start Of Frame Huffman - Differential sequential DCT (SOF5)', + 0xC6 => 'Start Of Frame Huffman - Differential progressive DCT (SOF6)', + 0xC7 => 'Start Of Frame Huffman - Differential spatial (SOF7)', + 0xC8 => 'Start Of Frame Arithmetic - Reserved for JPEG extensions (JPG)', + 0xC9 => 'Start Of Frame Arithmetic - Extended sequential DCT (SOF9)', + 0xCA => 'Start Of Frame Arithmetic - Progressive DCT (SOF10)', + 0xCB => 'Start Of Frame Arithmetic - Spatial (sequential) lossless (SOF11)', + 0xCD => 'Start Of Frame Arithmetic - Differential sequential DCT (SOF13)', + 0xCE => 'Start Of Frame Arithmetic - Differential progressive DCT (SOF14)', + 0xCF => 'Start Of Frame Arithmetic - Differential spatial (SOF15)', + 0xC4 => 'Define Huffman Table(s) (DHT)', + 0xCC => 'Define Arithmetic coding conditioning(s) (DAC)', + + 0xD0 => 'Restart with modulo 8 count 0 (RST0)', + 0xD1 => 'Restart with modulo 8 count 1 (RST1)', + 0xD2 => 'Restart with modulo 8 count 2 (RST2)', + 0xD3 => 'Restart with modulo 8 count 3 (RST3)', + 0xD4 => 'Restart with modulo 8 count 4 (RST4)', + 0xD5 => 'Restart with modulo 8 count 5 (RST5)', + 0xD6 => 'Restart with modulo 8 count 6 (RST6)', + 0xD7 => 'Restart with modulo 8 count 7 (RST7)', + + 0xD8 => 'Start of Image (SOI)', + 0xD9 => 'End of Image (EOI)', + 0xDA => 'Start of Scan (SOS)', + 0xDB => 'Define quantization Table(s) (DQT)', + 0xDC => 'Define Number of Lines (DNL)', + 0xDD => 'Define Restart Interval (DRI)', + 0xDE => 'Define Hierarchical progression (DHP)', + 0xDF => 'Expand Reference Component(s) (EXP)', + + 0xE0 => 'Application Field 0 (APP0) - usually JFIF or JFXX', + 0xE1 => 'Application Field 1 (APP1) - usually EXIF or XMP/RDF', + 0xE2 => 'Application Field 2 (APP2) - usually Flashpix', + 0xE3 => 'Application Field 3 (APP3)', + 0xE4 => 'Application Field 4 (APP4)', + 0xE5 => 'Application Field 5 (APP5)', + 0xE6 => 'Application Field 6 (APP6)', + 0xE7 => 'Application Field 7 (APP7)', + + 0xE8 => 'Application Field 8 (APP8)', + 0xE9 => 'Application Field 9 (APP9)', + 0xEA => 'Application Field 10 (APP10)', + 0xEB => 'Application Field 11 (APP11)', + 0xEC => 'Application Field 12 (APP12) - usually [picture info]', + 0xED => 'Application Field 13 (APP13) - usually photoshop IRB / IPTC', + 0xEE => 'Application Field 14 (APP14)', + 0xEF => 'Application Field 15 (APP15)', + + 0xF0 => 'Reserved for JPEG extensions (JPG0)', + 0xF1 => 'Reserved for JPEG extensions (JPG1)', + 0xF2 => 'Reserved for JPEG extensions (JPG2)', + 0xF3 => 'Reserved for JPEG extensions (JPG3)', + 0xF4 => 'Reserved for JPEG extensions (JPG4)', + 0xF5 => 'Reserved for JPEG extensions (JPG5)', + 0xF6 => 'Reserved for JPEG extensions (JPG6)', + 0xF7 => 'Reserved for JPEG extensions (JPG7)', + 0xF8 => 'Reserved for JPEG extensions (JPG8)', + 0xF9 => 'Reserved for JPEG extensions (JPG9)', + 0xFA => 'Reserved for JPEG extensions (JPG10)', + 0xFB => 'Reserved for JPEG extensions (JPG11)', + 0xFC => 'Reserved for JPEG extensions (JPG12)', + 0xFD => 'Reserved for JPEG extensions (JPG13)', + + 0xFE => 'Comment (COM)', + 0x01 => 'For temp private use arith code (TEM)', + 0x02 => 'Reserved (RES)', ]; private $data; private $start; private $type; - public function __construct($type, $start, $data) { $this->type = $type; @@ -138,6 +138,7 @@ public function getData() public function setData($data) { $this->data = $data; + return $this; } @@ -161,6 +162,7 @@ public function getStart() public function setStart($start) { $this->start = $start; + return $this; } @@ -184,6 +186,7 @@ public function getType() public function setType($type) { $this->type = $type; + return $this; } @@ -197,6 +200,7 @@ public function getName() if (isset(self::$segmentNames[$this->type])) { return self::$segmentNames[$this->type]; } + return ''; } @@ -210,11 +214,11 @@ public function getDescription() if (isset(self::$segmentDescriptions[$this->type])) { return self::$segmentDescriptions[$this->type]; } + return ''; } public function isXmpSegment() { - } } diff --git a/src/Format/PNG.php b/src/Format/PNG.php index 1c73792..f9a7222 100644 --- a/src/Format/PNG.php +++ b/src/Format/PNG.php @@ -1,9 +1,10 @@ @@ -55,7 +56,7 @@ public function __construct($contents, $filename = null) public function getBytes() { if ($this->xmp && ($this->xmp->hasChanges() || $this->hasNewXmp)) { - $data = "XML:com.adobe.xmp\x00\x00\x00\x00\x00" . $this->xmp->getString(); + $data = "XML:com.adobe.xmp\x00\x00\x00\x00\x00".$this->xmp->getString(); $xmpChunk = $this->getXmpChunk(); @@ -85,7 +86,7 @@ public function getBytes() */ public function getXmp() { - if (!$this->xmp) { + if (! $this->xmp) { $xmpChunk = $this->getXmpChunk(); if ($xmpChunk) { diff --git a/src/Format/PNG/Chunk.php b/src/Format/PNG/Chunk.php index 15742fb..fd284b4 100644 --- a/src/Format/PNG/Chunk.php +++ b/src/Format/PNG/Chunk.php @@ -1,4 +1,5 @@ getLength(), $this->type) . $this->data . $this->getCrc(); + return pack('Na4', $this->getLength(), $this->type).$this->data.$this->getCrc(); } /** @@ -63,7 +64,7 @@ public function getChunk() */ public function getCrc() { - $crc = crc32($this->type . $this->data); + $crc = crc32($this->type.$this->data); $hex = str_pad(dechex($crc), 8, '0', STR_PAD_LEFT); // pad to 4 bytes return hex2bin($hex); @@ -77,6 +78,7 @@ public function getCrc() public function setData($data) { $this->data = $data; + return $this; } } diff --git a/src/Format/PSD.php b/src/Format/PSD.php index 7e16e92..fa07df5 100644 --- a/src/Format/PSD.php +++ b/src/Format/PSD.php @@ -1,357 +1,356 @@ - - * @author Joel Bernerman - */ -class PSD extends Image { - - /** - * File signature. - */ - const FILE_SIGNATURE = "\x38\x42\x50\x53"; - - /** - * Image resource block signature. - */ - const IRB_SIGNATURE = "\x38\x42\x49\x4d"; - - /** - * Image resource IDs. - */ - const IRID_EXIF1 = "\x04\x22"; - const IRID_EXIF2 = "\x04\x23"; - const IRID_XMP = "\x04\x24"; - const IRID_IPTC = "\x04\x04"; - - private $fileheader; - private $IRBs; - private $eoIRS; - private $soIRS; - private $xmp; - private $exif; - private $iptc; - private $tmpHandle; - - /** - * - * @param type $fileHeader - * @param type $IRBs - * @param type $soIRS - * @param type $eoIRS - * @param type $filename - */ - private function __construct($fileHeader, $IRBs, $soIRS, $eoIRS, $tmpHandle, $filename = null) - { - - $this->IRBs = $IRBs; - $this->fileheader = $fileHeader; - $this->soIRS = $soIRS; - $this->eoIRS = $eoIRS; - $this->filename = $filename; - $this->tmpHandle = $tmpHandle; - } - - /** - * Set xmp data. - * @param Xmp $xmp - * - * @return $this - */ - public function setXmp(Xmp $xmp) - { - $this->xmp = $xmp; - $present = false; - foreach ($this->IRBs as $IRB) { - if ($IRB->getResourceId() === self::IRID_XMP) { - $IRB->setData($xmp->getString()); - $present = true; - } - } - // Add if not present. - if (!$present) { - $this->IRBs[] = new PSD\IRB(self::IRID_XMP, "\x00\x00", $xmp->getString()); - } - - return $this; - } - - /** - * @return string - */ - public function getBytes() - { - $stream = fopen('php://temp', 'r+'); - $this->write($stream); - - rewind($stream); - - $contents = stream_get_contents($stream); - - fclose($stream); - - return $contents; - } - - /** - * Save to file. - * - * @param string $filename - * @throws \Exception - * @return void - */ - public function save($filename = null) - { - $filename = $filename ? : $this->filename; - - // Attempt to open the new psd file - $handle = @fopen($filename, 'wb+'); - - // Check if the file opened successfully - if (!$handle) { - throw new \Exception(sprintf('Could not open file %s', $filename)); - } - - $this->write($handle); - fclose($handle); - } - - /** - * Write PSD data to a stream/file. - * - * @param $handle - */ - private function write($handle) - { - $IRBData = ''; - foreach ($this->IRBs as $IRB) { - $IRBData .= self::IRB_SIGNATURE; - $IRBData .= $IRB->getResourceId(); - $IRBData .= $IRB->getPascalString(); - $IRBData .= pack('N', $IRB->getLength()); - $IRBData .= $IRB->getData(); - // Add padding byte. - if ($IRB->getLength() & 1) { - $IRBData .= "\x00"; - } - } - $fileData = $this->fileheader . pack('N', strlen($IRBData)) . $IRBData; - - fwrite($handle, $fileData); - stream_copy_to_stream($this->tmpHandle, $handle, -1, $this->eoIRS); - fclose($this->tmpHandle); - - // Update tmp-file. - $this->tmpHandle = tmpfile(); - rewind($handle); - stream_copy_to_stream($handle, $this->tmpHandle); - - //update end of IRS - $this->eoIRS = $this->soIRS + 4 + strlen($IRBData); - } - - /** - * Load a PSD from a GD image resource. - * - * @param $gd - * @return self - */ - public static function fromResource($gd) - { - throw new UnsupportedException('GD does not support PSD files.'); - } - - /** - * Load PSD from string. - */ - public static function fromString($string) - { - $stream = fopen('php://temp', 'r+'); - fwrite($stream, $string); - rewind($stream); - - return self::fromStream($stream); - } - - /** - * Load PSD from Imagick. - */ - public static function fromImagick(\Imagick $imagick) - { - $imagick->setImageFormat('psd'); - return self::fromString($imagick->getImageBlob()); - } - - /** - * Load a PSD from a stream. - * - * @param resource $fileHandle - * @param string $filename - * - * @return self - * @throws \Exception - */ - public static function fromStream($fileHandle, $filename = null) - { - try { - // Read the first two characters - $fileHeader = fread($fileHandle, 4); - - // Check PSD file signature. - if ($fileHeader !== self::FILE_SIGNATURE) { - throw new \Exception('Could not find SIGNATURE, invalid PSD file.'); - } - - // Keep reading file header, 22 bytes we only need when writing changes. - $fileHeader .= fread($fileHandle, 22); - // Read Color mode Section. - $bsize = fread($fileHandle, 4); - $CMLength = unpack('Nsize', $bsize); - $fileHeader .= $bsize; - if ($CMLength['size'] > 0) { - $fileHeader .= fread($fileHandle, $CMLength['size']); - } - - // Save position of Image Resource Section start. - // From this location we will modify data. - $soIRS = ftell($fileHandle); - // Get Image resource section length. - $bIRSLength = fread($fileHandle, 4); - $IRSLength = unpack('Nsize', $bIRSLength); - // Save position of Image Resource Section end. - // This is the position to read from tempfile when saving modified. - $eoIRS = $soIRS + 4 + $IRSLength['size']; - - // Read Resource blocks then stop. - $IRBs = array(); - while (ftell($fileHandle) < $eoIRS) { - $IRBSignature = fread($fileHandle, 4); - if ($IRBSignature === self::IRB_SIGNATURE) { - // We have a Image resource block, Read Resource Block. - $IRBs[] = self::readResourceBlock($fileHandle); - } - } - - $tmpHandle = tmpfile(); - rewind($fileHandle); - stream_copy_to_stream($fileHandle, $tmpHandle); - return new self($fileHeader, $IRBs, $soIRS, $eoIRS, $tmpHandle, $filename); - } finally { - fclose($fileHandle); - } - return false; - } - - private static function readResourceBlock($fileHandle) - { - $resourceId = fread($fileHandle, 2); - $pascalString = fread($fileHandle, 1); - $pascalStringLength = unpack('Hsize', $pascalString); - $pascalStringLength = hexdec($pascalStringLength['size']); - if ($pascalStringLength == 0) { - // Padding to even bytes. - $pascalString .= fread($fileHandle, 1); - } - else { - $pascalString .= fread($fileHandle, $pascalStringLength); - // Padding to even bytes. - if ($pascalStringLength & 1) { - $pascalString .= fread($fileHandle, 1); - } - } - - $bRBsize = fread($fileHandle, 4); - $RBsize = unpack('Nsize', $bRBsize); - $resourceBlockData = fread($fileHandle, $RBsize['size']); - - // Content lenght is uneven, skip padding byte in file handle. - if ($RBsize['size'] & 1) { - fseek($fileHandle, 1, SEEK_CUR); - } - - return new PSD\IRB($resourceId, $pascalString, $resourceBlockData); - } - - /** - * Load a PSD from a file. - * - * @param $filename - * - * @return self - * @throws \Exception - */ - public static function fromFile($filename) - { - $fileHandle = @fopen($filename, 'rb+'); - - if (!$fileHandle) { - throw new \Exception(sprintf('Could not open file %s', $filename)); - } - - return self::fromStream($fileHandle, $filename); - } - - /** - * @return Xmp - */ - public function getXmp() - { - if (!$this->xmp) { - $present = false; - foreach ($this->IRBs as $IRB) { - if ($IRB->getResourceId() === self::IRID_XMP) { - $this->xmp = new Xmp($IRB->getData()); - $present = true; - break; - } - } - if (!$present) { - $this->xmp = new Xmp(); - } - } - - return $this->xmp; - } - - /** - * @return Exif - */ - public function getExif() - { - if (!$this->exif) { - foreach ($this->IRBs as $IRB) { - if ($IRB->getResourceId() == self::IRID_EXIF1) { - $this->exif = new Exif($IRB->getData()); - break; - } - } - } - - return $this->exif; - } - - /** - * @return Iptc - */ - public function getIptc() - { - if (!$this->iptc) { - foreach ($this->IRBs as $IRB) { - if ($IRB->getResourceId() == self::IRID_IPTC) { - $this->iptc = new Iptc($IRB->getData()); - break; - } - } - } - - return $this->iptc; - } - -} + + * @author Joel Bernerman + */ +class PSD extends Image +{ + /** + * File signature. + */ + const FILE_SIGNATURE = "\x38\x42\x50\x53"; + + /** + * Image resource block signature. + */ + const IRB_SIGNATURE = "\x38\x42\x49\x4d"; + + /** + * Image resource IDs. + */ + const IRID_EXIF1 = "\x04\x22"; + const IRID_EXIF2 = "\x04\x23"; + const IRID_XMP = "\x04\x24"; + const IRID_IPTC = "\x04\x04"; + + private $fileheader; + private $IRBs; + private $eoIRS; + private $soIRS; + private $xmp; + private $exif; + private $iptc; + private $tmpHandle; + + /** + * @param type $fileHeader + * @param type $IRBs + * @param type $soIRS + * @param type $eoIRS + * @param type $filename + */ + private function __construct($fileHeader, $IRBs, $soIRS, $eoIRS, $tmpHandle, $filename = null) + { + $this->IRBs = $IRBs; + $this->fileheader = $fileHeader; + $this->soIRS = $soIRS; + $this->eoIRS = $eoIRS; + $this->filename = $filename; + $this->tmpHandle = $tmpHandle; + } + + /** + * Set xmp data. + * @param Xmp $xmp + * + * @return $this + */ + public function setXmp(Xmp $xmp) + { + $this->xmp = $xmp; + $present = false; + foreach ($this->IRBs as $IRB) { + if ($IRB->getResourceId() === self::IRID_XMP) { + $IRB->setData($xmp->getString()); + $present = true; + } + } + // Add if not present. + if (! $present) { + $this->IRBs[] = new PSD\IRB(self::IRID_XMP, "\x00\x00", $xmp->getString()); + } + + return $this; + } + + /** + * @return string + */ + public function getBytes() + { + $stream = fopen('php://temp', 'r+'); + $this->write($stream); + + rewind($stream); + + $contents = stream_get_contents($stream); + + fclose($stream); + + return $contents; + } + + /** + * Save to file. + * + * @param string $filename + * @throws \Exception + * @return void + */ + public function save($filename = null) + { + $filename = $filename ?: $this->filename; + + // Attempt to open the new psd file + $handle = @fopen($filename, 'wb+'); + + // Check if the file opened successfully + if (! $handle) { + throw new \Exception(sprintf('Could not open file %s', $filename)); + } + + $this->write($handle); + fclose($handle); + } + + /** + * Write PSD data to a stream/file. + * + * @param $handle + */ + private function write($handle) + { + $IRBData = ''; + foreach ($this->IRBs as $IRB) { + $IRBData .= self::IRB_SIGNATURE; + $IRBData .= $IRB->getResourceId(); + $IRBData .= $IRB->getPascalString(); + $IRBData .= pack('N', $IRB->getLength()); + $IRBData .= $IRB->getData(); + // Add padding byte. + if ($IRB->getLength() & 1) { + $IRBData .= "\x00"; + } + } + $fileData = $this->fileheader.pack('N', strlen($IRBData)).$IRBData; + + fwrite($handle, $fileData); + stream_copy_to_stream($this->tmpHandle, $handle, -1, $this->eoIRS); + fclose($this->tmpHandle); + + // Update tmp-file. + $this->tmpHandle = tmpfile(); + rewind($handle); + stream_copy_to_stream($handle, $this->tmpHandle); + + //update end of IRS + $this->eoIRS = $this->soIRS + 4 + strlen($IRBData); + } + + /** + * Load a PSD from a GD image resource. + * + * @param $gd + * @return self + */ + public static function fromResource($gd) + { + throw new UnsupportedException('GD does not support PSD files.'); + } + + /** + * Load PSD from string. + */ + public static function fromString($string) + { + $stream = fopen('php://temp', 'r+'); + fwrite($stream, $string); + rewind($stream); + + return self::fromStream($stream); + } + + /** + * Load PSD from Imagick. + */ + public static function fromImagick(\Imagick $imagick) + { + $imagick->setImageFormat('psd'); + + return self::fromString($imagick->getImageBlob()); + } + + /** + * Load a PSD from a stream. + * + * @param resource $fileHandle + * @param string $filename + * + * @return self + * @throws \Exception + */ + public static function fromStream($fileHandle, $filename = null) + { + try { + // Read the first two characters + $fileHeader = fread($fileHandle, 4); + + // Check PSD file signature. + if ($fileHeader !== self::FILE_SIGNATURE) { + throw new \Exception('Could not find SIGNATURE, invalid PSD file.'); + } + + // Keep reading file header, 22 bytes we only need when writing changes. + $fileHeader .= fread($fileHandle, 22); + // Read Color mode Section. + $bsize = fread($fileHandle, 4); + $CMLength = unpack('Nsize', $bsize); + $fileHeader .= $bsize; + if ($CMLength['size'] > 0) { + $fileHeader .= fread($fileHandle, $CMLength['size']); + } + + // Save position of Image Resource Section start. + // From this location we will modify data. + $soIRS = ftell($fileHandle); + // Get Image resource section length. + $bIRSLength = fread($fileHandle, 4); + $IRSLength = unpack('Nsize', $bIRSLength); + // Save position of Image Resource Section end. + // This is the position to read from tempfile when saving modified. + $eoIRS = $soIRS + 4 + $IRSLength['size']; + + // Read Resource blocks then stop. + $IRBs = []; + while (ftell($fileHandle) < $eoIRS) { + $IRBSignature = fread($fileHandle, 4); + if ($IRBSignature === self::IRB_SIGNATURE) { + // We have a Image resource block, Read Resource Block. + $IRBs[] = self::readResourceBlock($fileHandle); + } + } + + $tmpHandle = tmpfile(); + rewind($fileHandle); + stream_copy_to_stream($fileHandle, $tmpHandle); + + return new self($fileHeader, $IRBs, $soIRS, $eoIRS, $tmpHandle, $filename); + } finally { + fclose($fileHandle); + } + + return false; + } + + private static function readResourceBlock($fileHandle) + { + $resourceId = fread($fileHandle, 2); + $pascalString = fread($fileHandle, 1); + $pascalStringLength = unpack('Hsize', $pascalString); + $pascalStringLength = hexdec($pascalStringLength['size']); + if ($pascalStringLength == 0) { + // Padding to even bytes. + $pascalString .= fread($fileHandle, 1); + } else { + $pascalString .= fread($fileHandle, $pascalStringLength); + // Padding to even bytes. + if ($pascalStringLength & 1) { + $pascalString .= fread($fileHandle, 1); + } + } + + $bRBsize = fread($fileHandle, 4); + $RBsize = unpack('Nsize', $bRBsize); + $resourceBlockData = fread($fileHandle, $RBsize['size']); + + // Content lenght is uneven, skip padding byte in file handle. + if ($RBsize['size'] & 1) { + fseek($fileHandle, 1, SEEK_CUR); + } + + return new PSD\IRB($resourceId, $pascalString, $resourceBlockData); + } + + /** + * Load a PSD from a file. + * + * @param $filename + * + * @return self + * @throws \Exception + */ + public static function fromFile($filename) + { + $fileHandle = @fopen($filename, 'rb+'); + + if (! $fileHandle) { + throw new \Exception(sprintf('Could not open file %s', $filename)); + } + + return self::fromStream($fileHandle, $filename); + } + + /** + * @return Xmp + */ + public function getXmp() + { + if (! $this->xmp) { + $present = false; + foreach ($this->IRBs as $IRB) { + if ($IRB->getResourceId() === self::IRID_XMP) { + $this->xmp = new Xmp($IRB->getData()); + $present = true; + break; + } + } + if (! $present) { + $this->xmp = new Xmp(); + } + } + + return $this->xmp; + } + + /** + * @return Exif + */ + public function getExif() + { + if (! $this->exif) { + foreach ($this->IRBs as $IRB) { + if ($IRB->getResourceId() == self::IRID_EXIF1) { + $this->exif = new Exif($IRB->getData()); + break; + } + } + } + + return $this->exif; + } + + /** + * @return Iptc + */ + public function getIptc() + { + if (! $this->iptc) { + foreach ($this->IRBs as $IRB) { + if ($IRB->getResourceId() == self::IRID_IPTC) { + $this->iptc = new Iptc($IRB->getData()); + break; + } + } + } + + return $this->iptc; + } +} diff --git a/src/Format/PSD/IRB.php b/src/Format/PSD/IRB.php index 126a6fc..7981249 100644 --- a/src/Format/PSD/IRB.php +++ b/src/Format/PSD/IRB.php @@ -1,70 +1,70 @@ - - */ -class IRB { - - protected $data; - protected $resourceId; - protected $pascalString; - - /** - * @param string $type - * @param string $data - */ - public function __construct($resourceId, $pascalString, $data) - { - $this->resourceId = $resourceId; - $this->data = $data; - $this->pascalString = $pascalString; - } - - /** - * @return string - */ - public function getData() - { - return $this->data; - } - - /** - * @return string - */ - public function getResourceId() - { - return $this->resourceId; - } - - /** - * @return string - */ - public function getPascalString() - { - return $this->pascalString; - } - - /** - * @return int - */ - public function getLength() - { - return strlen($this->data); - } - - /** - * @param string $data - * - * @return $this - */ - public function setData($data) - { - $this->data = $data; - return $this; - } - -} \ No newline at end of file + + */ +class IRB +{ + protected $data; + protected $resourceId; + protected $pascalString; + + /** + * @param string $type + * @param string $data + */ + public function __construct($resourceId, $pascalString, $data) + { + $this->resourceId = $resourceId; + $this->data = $data; + $this->pascalString = $pascalString; + } + + /** + * @return string + */ + public function getData() + { + return $this->data; + } + + /** + * @return string + */ + public function getResourceId() + { + return $this->resourceId; + } + + /** + * @return string + */ + public function getPascalString() + { + return $this->pascalString; + } + + /** + * @return int + */ + public function getLength() + { + return strlen($this->data); + } + + /** + * @param string $data + * + * @return $this + */ + public function setData($data) + { + $this->data = $data; + + return $this; + } +} diff --git a/src/Format/WebP.php b/src/Format/WebP.php index 591a68d..64162c1 100644 --- a/src/Format/WebP.php +++ b/src/Format/WebP.php @@ -1,10 +1,11 @@ @@ -50,7 +51,7 @@ public function __construct($contents, $filename = null) $this->chunks = $this->getChunksFromContents($contents); - if (!$this->isExtendedFormat()) { + if (! $this->isExtendedFormat()) { // throw new \Exception('Only extended WebP format is supported'); } @@ -62,7 +63,7 @@ public function __construct($contents, $filename = null) */ public function getXmp() { - if (!$this->xmp) { + if (! $this->xmp) { $chunk = $this->getXmpChunk(); if ($chunk) { @@ -136,7 +137,7 @@ private function getBitstreamChunk() */ public function getExif() { - if (!$this->exif) { + if (! $this->exif) { $chunk = $this->getExifChunk(); if ($chunk) { @@ -248,15 +249,14 @@ public function getBytes() } if ($hasExtendedFeatures) { - if (!$this->isExtendedFormat()) { + if (! $this->isExtendedFormat()) { // generate VP8X header - } return $this->getFile($this->chunks); - } else { $chunk = $this->getBitstreamChunk(); + return $this->getFile([$chunk]); } } @@ -274,8 +274,9 @@ private function getFile($chunks) $data .= $chunk->getChunk(); } - $header = 'RIFF' . pack('V', strlen($chunks) + 4) . 'WEBP'; - return $header . $data; + $header = 'RIFF'.pack('V', strlen($chunks) + 4).'WEBP'; + + return $header.$data; } /** @@ -284,6 +285,7 @@ private function getFile($chunks) private function isExtendedFormat() { $first = $this->chunks[0]; + return 'VP8X' === $first->getType(); } } diff --git a/src/Format/WebP/Chunk.php b/src/Format/WebP/Chunk.php index 4658476..cf8fa65 100644 --- a/src/Format/WebP/Chunk.php +++ b/src/Format/WebP/Chunk.php @@ -1,4 +1,5 @@ type . pack('V', $length) . $data; + return $this->type.pack('V', $length).$data; } /** @@ -74,6 +75,7 @@ public function getChunk() public function setData($data) { $this->data = $data; + return $this; } } diff --git a/src/Format/WebP/VP8XChunk.php b/src/Format/WebP/VP8XChunk.php index 293d592..615c035 100644 --- a/src/Format/WebP/VP8XChunk.php +++ b/src/Format/WebP/VP8XChunk.php @@ -1,4 +1,5 @@ data[0]); - return (bool) (($features[1] >> $n-1) & 1); + return (bool) (($features[1] >> $n - 1) & 1); } public function hasXmp() @@ -33,17 +34,14 @@ public function hasXmp() public function hasExif() { - $features = unpack('c', $this->data[0]); $byte = $features[1] & 4; var_dump($byte, $features[1]); - $this->data[0] = pack('c', $byte); - return $this->hasFeature(4); } } diff --git a/src/Image.php b/src/Image.php index 6e5528f..226f313 100644 --- a/src/Image.php +++ b/src/Image.php @@ -26,6 +26,7 @@ abstract class Image implements ImageInterface public function setFilename($filename) { $this->filename = $filename; + return $this; } @@ -62,7 +63,7 @@ public function save($filename = null) { $filename = $filename ?: $this->filename; - if (!$filename) { + if (! $filename) { throw new \Exception('Must provide a filename'); } diff --git a/src/ImageInterface.php b/src/ImageInterface.php index a50a1f6..ff2c505 100644 --- a/src/ImageInterface.php +++ b/src/ImageInterface.php @@ -1,10 +1,11 @@ ['xmp', 'iptc'], 'urgency' => ['xmp', 'iptc'], 'keywords' => ['xmp', 'iptc'], - 'dateCreated' => ['xmp', 'iptc'] + 'dateCreated' => ['xmp', 'iptc'], ]; /** @@ -51,7 +52,7 @@ class Aggregate private $priority; /** - * Constructor + * Constructor. * * @param Xmp $xmp * @param Iptc $iptc @@ -74,12 +75,13 @@ public function __construct(Xmp $xmp = null, Iptc $iptc = null, Exif $exif = nul public function setPriority(array $priority) { foreach ($priority as $metaType) { - if (!in_array($metaType, ['xmp', 'iptc', 'exif'], true)) { + if (! in_array($metaType, ['xmp', 'iptc', 'exif'], true)) { throw new \Exception('Priority can only contain xmp, iptc or exif'); } } $this->priority = $priority; + return $this; } @@ -92,17 +94,17 @@ private function get($field) { foreach ($this->priority as $metaType) { // check if this meta type is supported for this field - if (!in_array($metaType, $this->fields[$field], true)) { + if (! in_array($metaType, $this->fields[$field], true)) { continue; } $metaObject = $this->$metaType; - if (!$metaObject) { + if (! $metaObject) { continue; } - $getter = 'get' . ucfirst($field); + $getter = 'get'.ucfirst($field); $value = $metaObject->$getter(); if ($value) { @@ -126,11 +128,11 @@ private function set($field, $value) foreach ($supported as $metaType) { $metaObject = $this->$metaType; - if (!$metaObject) { + if (! $metaObject) { continue; } - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); $metaObject->$setter($value); } diff --git a/src/Metadata/Exif.php b/src/Metadata/Exif.php index 7969e30..b563006 100644 --- a/src/Metadata/Exif.php +++ b/src/Metadata/Exif.php @@ -1,4 +1,5 @@ decodeIFDField(substr($data, $pos, 2), 4); $pos += 2; @@ -101,7 +101,8 @@ private function decodeIFDField($field, $type) // to return multiple values instead of a single value echo "

Error - ASCII Strings should not be processed in get_IFD_Data_Type

\n"; - return "Error Should never get here"; //explode( "\x00", $input_data ); + + return 'Error Should never get here'; //explode( "\x00", $input_data ); } elseif ($type == 5) { // This is a Unsigned rational type @@ -177,25 +178,19 @@ private function decodeIFDField($field, $type) return $value; } // Check if this is a Float type - elseif ( $type == 11 ) - { + elseif ($type == 11) { // IEEE 754 Float // TODO - EXIF - IFD datatype Float not implemented yet - return "FLOAT NOT IMPLEMENTED YET"; + return 'FLOAT NOT IMPLEMENTED YET'; } // Check if this is a Double type - elseif ( $type == 12 ) - { + elseif ($type == 12) { // IEEE 754 Double // TODO - EXIF - IFD datatype Double not implemented yet - return "DOUBLE NOT IMPLEMENTED YET"; - } - else - { + return 'DOUBLE NOT IMPLEMENTED YET'; + } else { // Error - Invalid Datatype return "Invalid Datatype $type"; - } - } } diff --git a/src/Metadata/Exif2.php b/src/Metadata/Exif2.php index 115d9df..d5556cf 100644 --- a/src/Metadata/Exif2.php +++ b/src/Metadata/Exif2.php @@ -1,4 +1,5 @@ data['EXIF']['ISOSpeedRatings'])) { return $this->data['EXIF']['ISOSpeedRatings']; } + return null; } - + /** * Get aperture. * @@ -101,6 +104,7 @@ public function getAperture() } elseif (isset($this->data['XMP']['FNumber'])) { return (float) $this->data['XMP']['FNumber']; } + return null; } @@ -113,7 +117,7 @@ public function getExposureProgram() { if (isset($this->data['EXIF']['ExposureProgram'])) { $mode = $this->data['EXIF']['ExposureProgram']; - $modes = array( + $modes = [ 1 => 'Manual', 2 => 'Program', 3 => 'Aperture Priority', @@ -121,13 +125,14 @@ public function getExposureProgram() 5 => 'Creative', 6 => 'Action', 7 => 'Portrait', - 8 => 'Landscape' - ); + 8 => 'Landscape', + ]; if (isset($modes[$mode])) { return $modes[$mode]; } } + return null; } @@ -140,7 +145,7 @@ public function getWhiteBalance() { if (isset($this->data['EXIF']['WhiteBalance'])) { $mode = $this->data['EXIF']['WhiteBalance']; - $modes = array( + $modes = [ 0 => 'Auto', 1 => 'Daylight', 2 => 'Cloudy', @@ -161,20 +166,21 @@ public function getWhiteBalance() 18 => 'Custom 3', 19 => 'Custom 4', 20 => 'PC Set4', - 21 => 'PC Set5' - ); + 21 => 'PC Set5', + ]; if (isset($modes[$mode])) { return $modes[$mode]; } } + return null; } /** * Get exposure bias. * - * @return integer|null + * @return int|null */ public function getExposureBias() { @@ -187,6 +193,7 @@ public function getExposureBias() return $value; } } + return null; } @@ -200,6 +207,7 @@ public function getMake() if (isset($this->data['IFD0']['Make'])) { return trim($this->data['IFD0']['Make']); } + return null; } @@ -213,6 +221,7 @@ public function getModel() if (isset($this->data['IFD0']['Model'])) { return trim($this->data['IFD0']['Model']); } + return null; } @@ -226,7 +235,7 @@ public function getFlashMode() if (isset($this->data['EXIF']['Flash'])) { $mode = $this->data['EXIF']['Flash']; - $modes = array( + $modes = [ 0 => 'Flash did not fire', 1 => 'Flash fired', 5 => 'Strobe return light not detected', @@ -248,13 +257,14 @@ public function getFlashMode() 79 => 'Flash fired, compulsory flash mode, red-eye reduction mode, return light detected', 89 => 'Flash fired, auto mode, red-eye reduction mode', 93 => 'Flash fired, auto mode, return light not detected, red-eye reduction mode', - 95 => 'Flash fired, auto mode, return light detected, red-eye reduction mode' - ); + 95 => 'Flash fired, auto mode, return light detected, red-eye reduction mode', + ]; if (isset($modes[$mode])) { return $modes[$mode]; } } + return null; } @@ -285,7 +295,7 @@ public function getCamera() return $model; } - return trim($make . ' ' . $model); + return trim($make.' '.$model); } /** @@ -298,6 +308,7 @@ public function getShutterSpeed() if (isset($this->data['EXIF']['ExposureTime'])) { return $this->fractionToDecimal($this->data['EXIF']['ExposureTime']); } + return null; } @@ -311,6 +322,7 @@ public function getDateTime() if (isset($this->data['DateTimeDigitized'])) { return $this->fractionToDecimal($this->data['DateTimeDigitized']); } + return null; } @@ -324,6 +336,7 @@ public function getFocalLength() if (isset($this->data['EXIF']['FocalLength'])) { return $this->fractionToDecimal($this->data['EXIF']['FocalLength']); } + return null; } @@ -345,6 +358,7 @@ public function getLensModel() if ($lens && stripos($lens, 'Unknown') !== 0) { return $lens; } + return null; } @@ -365,11 +379,12 @@ public function getSoftware() if ($software != null) { $software = trim($software); - + if (preg_match('#^v?[0-9\.]*$#', $software)) { $software = null; } } + return $software; } @@ -387,13 +402,14 @@ public function getColorMode() } elseif (isset($this->data['EXIF']['ColorSpace']) && $this->data['EXIF']['ColorSpace'] == 'sRGB') { return 'RGB'; } + return null; } /** * Get GPS coordinates. * - * @return array|null + * @return array|null */ public function getGPS() { @@ -404,11 +420,12 @@ public function getGPS() $latitude = $this->getGPSPart($this->data['GPS']['GPSLatitude'], $this->data['GPS']['GPSLatitudeRef']); $longitude = $this->getGPSPart($this->data['GPS']['GPSLongitude'], $this->data['GPS']['GPSLongitudeRef']); - return array( + return [ 'latitude' => $latitude, - 'longitude' => $longitude - ); + 'longitude' => $longitude, + ]; } + return null; } @@ -426,6 +443,7 @@ protected function fractionToDecimal($string) if (count($result) == 2) { return (float) $result[0] / (float) $result[1]; } + return $string; } @@ -439,24 +457,24 @@ protected function fractionToDecimal($string) */ protected function getGPSPart($exifCoord, $ref) { - $degrees = count($exifCoord) > 0? $this->fractionToDecimal($exifCoord[0]) : 0; - $minutes = count($exifCoord) > 1? $this->fractionToDecimal($exifCoord[1]) : 0; - $seconds = count($exifCoord) > 2? $this->fractionToDecimal($exifCoord[2]) : 0; + $degrees = count($exifCoord) > 0 ? $this->fractionToDecimal($exifCoord[0]) : 0; + $minutes = count($exifCoord) > 1 ? $this->fractionToDecimal($exifCoord[1]) : 0; + $seconds = count($exifCoord) > 2 ? $this->fractionToDecimal($exifCoord[2]) : 0; // store human readable string - $string = $degrees . '°' . $minutes . '′' . $seconds . '″' . $ref; + $string = $degrees.'°'.$minutes.'′'.$seconds.'″'.$ref; // calculate the coordinates for use in maps etc. - $flip = ($ref == 'W' || $ref == 'S')? -1 : 1; + $flip = ($ref == 'W' || $ref == 'S') ? -1 : 1; $coordinates = $flip * ($degrees + $minutes / 60 + $seconds / 3600); - return array( + return [ 'degrees' => $degrees, 'minutes' => $minutes, 'seconds' => $seconds, 'reference' => $ref, 'string' => $string, - 'coordinates' => $coordinates - ); + 'coordinates' => $coordinates, + ]; } } diff --git a/src/Metadata/Iptc.php b/src/Metadata/Iptc.php index a1d048b..0316fd7 100644 --- a/src/Metadata/Iptc.php +++ b/src/Metadata/Iptc.php @@ -1,4 +1,5 @@ getSegmentsByName('APP13'); $irb = ''; @@ -150,14 +144,14 @@ public static function fromJPEG(JPEG $jpeg) } } - $dataArray = array(); + $dataArray = []; if ($irb) { $pos = 0; // Cycle through the IRB and extract its records // Records are started with 8BIM, so cycle until no more instances of 8BIM can be found - while (($pos < strlen($irb)) && (($pos = strpos($irb, "8BIM", $pos)) !== false)) { + while (($pos < strlen($irb)) && (($pos = strpos($irb, '8BIM', $pos)) !== false)) { $pos += 4; // skip over the 8BIM characters $id = ord($irb[$pos]) * 256 + ord($irb[$pos + 1]); // next two characters are record ID @@ -204,8 +198,8 @@ public static function fromJPEG(JPEG $jpeg) // Get the description for this resource // Check if this is a Path information Resource, since they have a range of ID's - if (($id >= 0x07D0 ) && ($id <= 0x0BB6)) { - $ResDesc = "ID Info : Path Information (saved paths)."; + if (($id >= 0x07D0) && ($id <= 0x0BB6)) { + $ResDesc = 'ID Info : Path Information (saved paths).'; } else { /* if (array_key_exists($id, $GLOBALS[ "Photoshop_ID_Descriptions" ])) { @@ -213,7 +207,7 @@ public static function fromJPEG(JPEG $jpeg) } else {*/ - $ResDesc = ""; + $ResDesc = ''; //} } /* @@ -224,15 +218,15 @@ public static function fromJPEG(JPEG $jpeg) } else {*/ - $ResName = ""; + $ResName = ''; //} // Store the Resource in the array to be returned - $dataArray[] = ["ResID" => $id, - "ResName" => $ResName, - "ResDesc" => $ResDesc, - "ResEmbeddedName" => $resembeddedname, - "ResData" => $resdata ]; + $dataArray[] = ['ResID' => $id, + 'ResName' => $ResName, + 'ResDesc' => $ResDesc, + 'ResEmbeddedName' => $resembeddedname, + 'ResData' => $resdata, ]; // Jump over the data to the next record $pos += $storedSize; @@ -255,13 +249,13 @@ public static function fromFile($path) { @getimagesize($path, $info); - $iptc = (isset($info['APP13']))? iptcparse($info['APP13']): []; + $iptc = (isset($info['APP13'])) ? iptcparse($info['APP13']) : []; $data = []; foreach ($iptc as $field => $values) { // convert values to UTF-8 if needed for ($i = 0; $i < count($values); $i++) { - if (!self::seemsUtf8($values[$i])) { + if (! self::seemsUtf8($values[$i])) { $values[$i] = utf8_decode($values[$i]); } } @@ -275,7 +269,7 @@ public static function fromFile($path) * Returns data for the given IPTC field. Returns null if the field does not exist. * * @param string $field The field to return. - * @param boolean $single Return the first value or all values in field. Defaults to single (true). + * @param bool $single Return the first value or all values in field. Defaults to single (true). * * @return string|null */ @@ -284,7 +278,7 @@ private function get($field, $single = true) $code = $this->fields[$field]; if (isset($this->data[$code])) { - return ($single)? $this->data[$code][0]: $this->data[$code]; + return ($single) ? $this->data[$code][0] : $this->data[$code]; } return null; @@ -675,8 +669,9 @@ public function getDateCreated() $time = $this->get('time'); if ($date && $time) { - return new \DateTime($date . ' ' . $time); + return new \DateTime($date.' '.$time); } + return null; } @@ -704,7 +699,7 @@ public function all() } /** - * @return boolean + * @return bool */ public function hasChanges() { diff --git a/src/Metadata/Panorama/GPano.php b/src/Metadata/Panorama/GPano.php index 617a063..13bc687 100644 --- a/src/Metadata/Panorama/GPano.php +++ b/src/Metadata/Panorama/GPano.php @@ -139,7 +139,8 @@ public function get() return $this->attributes; } - public function getIterator() { + public function getIterator() + { return new ArrayIterator($this->attributes); } } diff --git a/src/Metadata/UnsupportedException.php b/src/Metadata/UnsupportedException.php index c0e5a0d..2024144 100644 --- a/src/Metadata/UnsupportedException.php +++ b/src/Metadata/UnsupportedException.php @@ -1,4 +1,5 @@ self::XMP_RIGHTS_NS, 'Iptc4xmpCore' => self::IPTC4_XMP_CORE_NS, 'Iptc4xmpExt' => self::IPTC4_XMP_EXT_NS, - 'photomechanic' => self::PHOTO_MECHANIC_NS + 'photomechanic' => self::PHOTO_MECHANIC_NS, ]; /** @@ -102,7 +79,7 @@ public function __construct($data = null, $formatOutput = false) $this->dom->formatOutput = $formatOutput; $this->dom->substituteEntities = false; - if (!$data) { + if (! $data) { $data = ''; } @@ -138,6 +115,7 @@ public function __construct($data = null, $formatOutput = false) public function setFormatOutput($formatOutput) { $this->dom->formatOutput = $formatOutput; + return $this; } @@ -169,7 +147,7 @@ public static function fromArray($array) $xmp = new self; foreach ($array as $field => $value) { - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); if (method_exists($xmp, $setter) && null !== $value) { $xmp->$setter($value); @@ -191,7 +169,7 @@ private function getNode($field, $ns, $checkAttributes = true) $rdfDesc = $this->getRDFDescription($ns); // check for field as an element or an attribute - $query = ($checkAttributes)? $field . '|@' . $field: $field; + $query = ($checkAttributes) ? $field.'|@'.$field : $field; $result = $this->xpath->query($query, $rdfDesc); if ($result->length) { @@ -216,6 +194,7 @@ private function getAttr($field, $namespace) if ($node) { return $node->nodeValue; } + return null; } @@ -421,12 +400,12 @@ private function getOrCreateRDFDescription($namespace) $prefix = array_search($namespace, $this->namespaces); $desc = $this->dom->createElementNS(self::RDF_NS, 'rdf:Description'); - $desc->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $prefix, $namespace); + $desc->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:'.$prefix, $namespace); $rdf = $this->xpath->query('rdf:RDF', $this->dom->documentElement)->item(0); // check if rdf:RDF element exists, and create it if not - if (!$rdf) { + if (! $rdf) { $rdf = $this->dom->createElementNS(self::RDF_NS, 'rdf:RDF'); $this->dom->documentElement->appendChild($rdf); } @@ -482,7 +461,7 @@ private function setSeq($field, $value, $ns) */ private function setList($field, $value, $type, $ns) { - $result = $this->xpath->query('//rdf:Description/' . $field . '/' . $type . '/rdf:li'); + $result = $this->xpath->query('//rdf:Description/'.$field.'/'.$type.'/rdf:li'); $parent = null; if ($result->length) { @@ -504,8 +483,7 @@ private function setList($field, $value, $type, $ns) $node->appendChild($parent); } - - if (!$value || (!is_array($value) && count($value) == 0)) { + if (! $value || (! is_array($value) && count($value) == 0)) { // remove element $parent->parentNode->parentNode->removeChild($parent->parentNode); } else { @@ -702,6 +680,7 @@ public function getPhotographerName() if (is_array($seq)) { return $seq[0]; } + return $seq; } @@ -1020,11 +999,11 @@ private function getContactInfo($field) { $contactInfo = $this->getNode('Iptc4xmpCore:CreatorContactInfo', self::IPTC4_XMP_CORE_NS); - if (!$contactInfo) { + if (! $contactInfo) { return null; } - $node = $this->xpath->query($field . '|@' . $field, $contactInfo); + $node = $this->xpath->query($field.'|@'.$field, $contactInfo); if ($node->length) { return $node->item(0)->nodeValue; @@ -1219,7 +1198,7 @@ public function getDateCreated() { $date = $this->getAttr('photoshop:DateCreated', self::PHOTOSHOP_NS); - if (!$date) { + if (! $date) { return null; } @@ -1266,6 +1245,7 @@ public function getAbout() public function setAbout($about) { $this->about = $about; + return $this; } @@ -1291,6 +1271,7 @@ public function getToolkit() public function setToolkit($toolkit) { $this->dom->documentElement->setAttributeNS('adobe:ns:meta/', 'x:xmptk', $toolkit); + return $this; } @@ -1313,7 +1294,7 @@ public function getString() } } - if (!$hasBegin) { + if (! $hasBegin) { $this->dom->insertBefore( $this->dom->createProcessingInstruction( 'xpacket', @@ -1323,7 +1304,7 @@ public function getString() ); } - if (!$hasEnd) { + if (! $hasEnd) { $this->dom->appendChild($this->dom->createProcessingInstruction('xpacket', 'end="w"')); // append to end } diff --git a/tests/Format/AbstractImageTest.php b/tests/Format/AbstractImageTest.php index b99256f..c0e77f3 100644 --- a/tests/Format/AbstractImageTest.php +++ b/tests/Format/AbstractImageTest.php @@ -2,13 +2,13 @@ namespace Ycs77\ImageMetadata\Tests\Format; +use Mockery as M; use Ycs77\ImageMetadata\Image; use Ycs77\ImageMetadata\Metadata\Aggregate; use Ycs77\ImageMetadata\Metadata\Exif; use Ycs77\ImageMetadata\Metadata\Iptc; use Ycs77\ImageMetadata\Metadata\UnsupportedException; use Ycs77\ImageMetadata\Metadata\Xmp; -use Mockery as M; /** * @author Daniel Chesterton diff --git a/tests/Format/JPEGTest.php b/tests/Format/JPEGTest.php index 0c6edda..a2f1248 100644 --- a/tests/Format/JPEGTest.php +++ b/tests/Format/JPEGTest.php @@ -17,7 +17,7 @@ class JPEGTest extends \PHPUnit_Framework_TestCase */ public function testGetXmpPhotoMechanic() { - $jpeg = JPEG::fromFile(__DIR__ . '/../Fixtures/metapm.jpg'); + $jpeg = JPEG::fromFile(__DIR__.'/../Fixtures/metapm.jpg'); $xmp = $jpeg->getXmp(); @@ -30,7 +30,7 @@ public function testGetXmpPhotoMechanic() */ public function testGetXmpPhotoshop() { - $jpeg = JPEG::fromFile(__DIR__ . '/../Fixtures/metaphotoshop.jpg'); + $jpeg = JPEG::fromFile(__DIR__.'/../Fixtures/metaphotoshop.jpg'); $xmp = $jpeg->getXmp(); @@ -43,7 +43,7 @@ public function testGetXmpPhotoshop() */ public function testGetXmpNoMeta() { - $jpeg = JPEG::fromFile(__DIR__ . '/../Fixtures/nometa.jpg'); + $jpeg = JPEG::fromFile(__DIR__.'/../Fixtures/nometa.jpg'); $xmp = $jpeg->getXmp(); diff --git a/tests/Format/PNGTest.php b/tests/Format/PNGTest.php index 122999e..adb4ae9 100644 --- a/tests/Format/PNGTest.php +++ b/tests/Format/PNGTest.php @@ -22,7 +22,7 @@ class PNGTest extends \PHPUnit_Framework_TestCase */ public function testFromFileInvalidPNG() { - PNG::fromFile(__DIR__ . '/../Fixtures/nometa.jpg'); + PNG::fromFile(__DIR__.'/../Fixtures/nometa.jpg'); } /** @@ -31,7 +31,7 @@ public function testFromFileInvalidPNG() */ public function testGetXmpWithMetadataWrittenInPhotoshop() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/metaphotoshop.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/metaphotoshop.png'); $xmp = $png->getXmp(); @@ -45,7 +45,7 @@ public function testGetXmpWithMetadataWrittenInPhotoshop() */ public function testGetXmpWithMetaWrittenInPhotoMechanic() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/metapm.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/metapm.png'); $xmp = $png->getXmp(); @@ -59,7 +59,7 @@ public function testGetXmpWithMetaWrittenInPhotoMechanic() */ public function testGetXmpNoMeta() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/nometa.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/nometa.png'); $xmp = $png->getXmp(); @@ -80,7 +80,7 @@ public function testGetXmpNoMeta() */ public function testFromFileValidPNG() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/nometa.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/nometa.png'); $this->assertInstanceOf(PNG::class, $png); } @@ -93,7 +93,7 @@ public function testFromFileValidPNG() */ public function testFromFileWithMalformedChunks() { - PNG::fromFile(__DIR__ . '/../Fixtures/malformedchunks.png'); + PNG::fromFile(__DIR__.'/../Fixtures/malformedchunks.png'); } /** @@ -101,7 +101,7 @@ public function testFromFileWithMalformedChunks() */ public function testSavePNGWithNewMetaData() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/nometa.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/nometa.png'); $png->getXmp()->setHeadline('PHP headline'); @@ -118,7 +118,7 @@ public function testSavePNGWithNewMetaData() */ public function testSavePNGWithUpdatedMetaData() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/metapm.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/metapm.png'); $png->getXmp()->setHeadline('PHP headline'); $tmp = tempnam(sys_get_temp_dir(), 'PNG'); @@ -140,7 +140,7 @@ public function testSavePNGWithNewXmpObject() $xmp = new Xmp; $xmp->setHeadline('PHP headline'); - $png = PNG::fromFile(__DIR__ . '/../Fixtures/nometa.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/nometa.png'); $png->setXmp($xmp); $png->save($tmp); @@ -153,7 +153,7 @@ public function testSavePNGWithNewXmpObject() */ public function testSavePNGWithoutChanges() { - $file = __DIR__ . '/../Fixtures/nometa.png'; + $file = __DIR__.'/../Fixtures/nometa.png'; $tmp = tempnam(sys_get_temp_dir(), 'PNG'); $png = PNG::fromFile($file); @@ -170,7 +170,7 @@ public function testSavePNGWithoutChanges() */ public function testGetExif() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/nometa.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/nometa.png'); $png->getExif(); } @@ -182,7 +182,7 @@ public function testGetExif() */ public function testGetIptc() { - $png = PNG::fromFile(__DIR__ . '/../Fixtures/nometa.png'); + $png = PNG::fromFile(__DIR__.'/../Fixtures/nometa.png'); $png->getIptc(); } } diff --git a/tests/Format/PSDTest.php b/tests/Format/PSDTest.php index 8bea33b..6a3f90b 100644 --- a/tests/Format/PSDTest.php +++ b/tests/Format/PSDTest.php @@ -1,37 +1,38 @@ -getXmp(); - - $this->assertInstanceOf(Xmp::class, $xmp); - $this->assertSame('Headline', $xmp->getHeadline()); - } - - /** - * Test that PSD class returns an empty XMP object when there is no XMP data. - */ - public function testGetXmpNoMeta() - { - $psd = PSD::fromFile(__DIR__ . '/../Fixtures/nometa.psd'); - - $xmp = $psd->getXmp(); - - $this->assertInstanceOf(Xmp::class, $xmp); - $this->assertNull($xmp->getHeadline()); - } -} \ No newline at end of file +getXmp(); + + $this->assertInstanceOf(Xmp::class, $xmp); + $this->assertSame('Headline', $xmp->getHeadline()); + } + + /** + * Test that PSD class returns an empty XMP object when there is no XMP data. + */ + public function testGetXmpNoMeta() + { + $psd = PSD::fromFile(__DIR__.'/../Fixtures/nometa.psd'); + + $xmp = $psd->getXmp(); + + $this->assertInstanceOf(Xmp::class, $xmp); + $this->assertNull($xmp->getHeadline()); + } +} diff --git a/tests/Format/WebPTest.php b/tests/Format/WebPTest.php index 9cc7aea..1923163 100644 --- a/tests/Format/WebPTest.php +++ b/tests/Format/WebPTest.php @@ -24,12 +24,12 @@ class WebPTest extends \PHPUnit_Framework_TestCase */ public function testFromFileInvalidWebP() { - WebP::fromFile(__DIR__ . '/../Fixtures/nometa.jpg'); + WebP::fromFile(__DIR__.'/../Fixtures/nometa.jpg'); } public function testFromFile() { - $webp = WebP::fromFile(__DIR__ . '/../Fixtures/meta.webp'); + $webp = WebP::fromFile(__DIR__.'/../Fixtures/meta.webp'); $this->assertInstanceOf(WebP::class, $webp); $xmp = $webp->getXmp(); @@ -42,7 +42,7 @@ public function testChangeXmp() { $tmp = tempnam(sys_get_temp_dir(), 'WebP'); - $webp = WebP::fromFile(__DIR__ . '/../Fixtures/meta.webp'); + $webp = WebP::fromFile(__DIR__.'/../Fixtures/meta.webp'); $webp->getXmp()->setHeadline('PHP headline'); $webp->save($tmp); @@ -53,7 +53,7 @@ public function testChangeXmp() public function testGetExif() { - $webp = WebP::fromFile(__DIR__ . '/../Fixtures/exif.webp'); + $webp = WebP::fromFile(__DIR__.'/../Fixtures/exif.webp'); $exif = $webp->getExif(); $this->assertInstanceOf(Exif::class, $exif); @@ -69,7 +69,7 @@ public function testGetExif() */ public function testGetIptc() { - $webp = WebP::fromFile(__DIR__ . '/../Fixtures/meta.webp'); + $webp = WebP::fromFile(__DIR__.'/../Fixtures/meta.webp'); $webp->getIptc(); } @@ -79,7 +79,7 @@ public function testGetIptc() */ public function ttestSimpleUnsupported() { - WebP::fromFile(__DIR__ . '/../Fixtures/simple.webp'); + WebP::fromFile(__DIR__.'/../Fixtures/simple.webp'); } public function testConvertsFromSimpleFormat() @@ -87,7 +87,7 @@ public function testConvertsFromSimpleFormat() // todo: mock Xmp class $xmp = new Xmp; - $webp = WebP::fromFile(__DIR__ . '/../Fixtures/simple.webp'); + $webp = WebP::fromFile(__DIR__.'/../Fixtures/simple.webp'); $webp->setXmp($xmp); var_dump($webp->getBytes()); diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 17cafb6..8f43138 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -2,9 +2,9 @@ namespace Ycs77\ImageMetadata\Tests; -use Ycs77\ImageMetadata\Image; -use Ycs77\ImageMetadata\Format\PNG; use Ycs77\ImageMetadata\Format\JPEG; +use Ycs77\ImageMetadata\Format\PNG; +use Ycs77\ImageMetadata\Image; /** * @author Daniel Chesterton @@ -18,7 +18,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testPNG() { - $image = Image::fromFile(__DIR__ . '/Fixtures/nometa.png'); + $image = Image::fromFile(__DIR__.'/Fixtures/nometa.png'); $this->assertInstanceOf(PNG::class, $image); } @@ -27,7 +27,7 @@ public function testPNG() */ public function testJPG() { - $image = Image::fromFile(__DIR__ . '/Fixtures/nometa.jpg'); + $image = Image::fromFile(__DIR__.'/Fixtures/nometa.jpg'); $this->assertInstanceOf(JPEG::class, $image); } @@ -36,7 +36,7 @@ public function testJPG() */ public function testUppercase() { - $image = Image::fromFile(__DIR__ . '/Fixtures/UPPERCASE.JPG'); + $image = Image::fromFile(__DIR__.'/Fixtures/UPPERCASE.JPG'); $this->assertInstanceOf(JPEG::class, $image); } @@ -45,7 +45,7 @@ public function testUppercase() */ public function testJPEG() { - $image = Image::fromFile(__DIR__ . '/Fixtures/nometa.jpeg'); + $image = Image::fromFile(__DIR__.'/Fixtures/nometa.jpeg'); $this->assertInstanceOf(JPEG::class, $image); } diff --git a/tests/Metadata/AggregateTest.php b/tests/Metadata/AggregateTest.php index 1f82701..d3988c9 100644 --- a/tests/Metadata/AggregateTest.php +++ b/tests/Metadata/AggregateTest.php @@ -1,13 +1,12 @@ shouldReceive($method)->once()->andReturn($xmpValue); @@ -83,7 +82,7 @@ public function testGetXmpIptcField($field) */ public function testXmpIptcFallThrough($field) { - $method = 'get' . ucfirst($field); + $method = 'get'.ucfirst($field); $xmp = M::mock(Xmp::class); $xmp->shouldReceive($method)->once()->andReturnNull(); @@ -106,7 +105,7 @@ public function testNullWhenNoProviders($field) { $reader = new Aggregate; - $getter = 'get' . ucfirst($field); + $getter = 'get'.ucfirst($field); $this->assertNull($reader->$getter()); } @@ -116,8 +115,8 @@ public function testNullWhenNoProviders($field) */ public function testSetXmpIptcField($field) { - $method = 'set' . ucfirst($field); - $value = ($field == 'dateCreated')? new \DateTime: 'value'; + $method = 'set'.ucfirst($field); + $value = ($field == 'dateCreated') ? new \DateTime : 'value'; $xmp = M::mock(Xmp::class); $xmp->shouldReceive($method)->once()->with($value); @@ -137,8 +136,8 @@ public function testSetXmpIptcField($field) */ public function testSetXmpIptcFieldWhenNoProviders($field) { - $method = 'set' . ucfirst($field); - $value = ($field == 'dateCreated')? new \DateTime: 'value'; + $method = 'set'.ucfirst($field); + $value = ($field == 'dateCreated') ? new \DateTime : 'value'; $aggregate = new Aggregate; diff --git a/tests/Metadata/IptcTest.php b/tests/Metadata/IptcTest.php index 30923f0..b6eb4f1 100644 --- a/tests/Metadata/IptcTest.php +++ b/tests/Metadata/IptcTest.php @@ -1,4 +1,5 @@ meta = Iptc::fromFile(__DIR__ . '/../Fixtures/metapm.jpg'); + $this->meta = Iptc::fromFile(__DIR__.'/../Fixtures/metapm.jpg'); } /** @@ -46,7 +47,7 @@ public function getMetaFields() ['supplementalCategories'], ['transmissionReference'], ['urgency'], - ['keywords'] + ['keywords'], ]; } @@ -72,7 +73,7 @@ public function tsestCaption() public function tesstKeywords() { $this->assertEquals( - 'Canvey Island, Carshalton Athletic, England, Essex, Football, Ryman Isthmian Premier League, Soccer, ' . + 'Canvey Island, Carshalton Athletic, England, Essex, Football, Ryman Isthmian Premier League, Soccer, '. 'Sport, Sports, The Prospects Stadium', $this->meta->getKeywords() ); @@ -88,7 +89,7 @@ public function tesstCategory() */ public function testGetSetMeta($field) { - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); $value = 'test'; @@ -97,7 +98,7 @@ public function testGetSetMeta($field) $this->assertSame($iptc, $return); - $getter = 'get' . ucfirst($field); + $getter = 'get'.ucfirst($field); $this->assertSame($value, $iptc->$getter()); } @@ -107,7 +108,7 @@ public function testGetSetMeta($field) */ public function testHasChanges($field) { - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); $value = 'test'; @@ -125,7 +126,7 @@ public function testHasChanges($field) */ public function testNull($field) { - $getter = 'get' . ucfirst($field); + $getter = 'get'.ucfirst($field); $iptc = new Iptc; diff --git a/tests/Metadata/XmpTest.php b/tests/Metadata/XmpTest.php index cac8a90..438a75f 100644 --- a/tests/Metadata/XmpTest.php +++ b/tests/Metadata/XmpTest.php @@ -1,8 +1,7 @@ getXmpFromFile(); $this->assertEquals($value, $xmp->$getter()); @@ -157,10 +156,10 @@ public function testSetBagFields($field, $xmlField) public function testSetAttrFields($field, $xmlField) { $value = 'A test string, with utf €åƒ∂, and some xml chars such as <>"'; - $expectedAttr = $xmlField . '="A test string, with utf €åƒ∂, and some xml chars such as <>""'; - $expectedElement = '<' . $xmlField . '>A test string, with utf €åƒ∂, and some xml chars such as <>"'; + $expectedAttr = $xmlField.'="A test string, with utf €åƒ∂, and some xml chars such as <>""'; + $expectedElement = '<'.$xmlField.'>A test string, with utf €åƒ∂, and some xml chars such as <>"'; - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); // test with no meta data $xmp = new Xmp; @@ -239,7 +238,7 @@ public function testXmpContainsProcessingInstructions() */ public function testFromArray($field, $value) { - $getter = 'get' . ucfirst($field); + $getter = 'get'.ucfirst($field); $xmp = Xmp::fromArray([$field => $value]); @@ -251,7 +250,7 @@ public function testFromArray($field, $value) */ public function testGetNonExistentValue($field) { - $getter = 'get' . ucfirst($field); + $getter = 'get'.ucfirst($field); $xmp = new Xmp; $this->assertNull($xmp->$getter()); @@ -264,7 +263,7 @@ public function testGetNonExistentValue($field) */ public function testHasChanges($field, $value) { - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); $xmp = new Xmp; @@ -400,7 +399,7 @@ public function testDeleteList() */ public function testSetNullAttribute($field, $xmlField) { - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); $xmp = new Xmp; $xmp->$setter($field); @@ -457,7 +456,6 @@ public function testDateCreated() '); $this->assertFalse($xmp->getDateCreated()); - } /** @@ -475,7 +473,7 @@ public function testInvalidXmlException() */ public function testFromFile() { - $this->assertInstanceOf(Xmp::class, Xmp::fromFile(__DIR__ . '/../Fixtures/all.XMP')); + $this->assertInstanceOf(Xmp::class, Xmp::fromFile(__DIR__.'/../Fixtures/all.XMP')); } /** @@ -495,17 +493,17 @@ private function assertXmpContainsProcessingInstructions(Xmp $xmp) */ private function assertValidList($type, $field, $xmlField, $value) { - $attributes = ($type == 'rdf:Alt')? ' xml:lang="x-default"': ''; + $attributes = ($type == 'rdf:Alt') ? ' xml:lang="x-default"' : ''; - $expected = '<' . $xmlField . '><' . $type . '>'; + $expected = '<'.$xmlField.'><'.$type.'>'; foreach ((array) $value as $li) { - $expected .= '' . $li . ''; + $expected .= ''.$li.''; } - $expected .= ''; + $expected .= ''; - $setter = 'set' . ucfirst($field); + $setter = 'set'.ucfirst($field); $xmp = new Xmp; $xmp->$setter($value); @@ -532,7 +530,7 @@ private function assertValidList($type, $field, $xmlField, $value) */ private function getXmpFromFile() { - return new Xmp(file_get_contents(__DIR__ . '/../Fixtures/all.XMP')); + return new Xmp(file_get_contents(__DIR__.'/../Fixtures/all.XMP')); } /** @@ -542,6 +540,6 @@ private function getXmpFromFile() */ private function getXmpFromFile2() { - return new Xmp(file_get_contents(__DIR__ . '/../Fixtures/all2.XMP')); + return new Xmp(file_get_contents(__DIR__.'/../Fixtures/all2.XMP')); } }