/** * {@inheritdoc} */ public function analyze($filename) { $imageSize = @getimagesize($filename); if ($imageSize === false) { throw new UnsupportedFileException('File type not supported.'); } $imageInfo = new ImageInfo(); $type = null; $colors = null; if ($imageSize[2] === IMAGETYPE_JPEG) { $gd = imagecreatefromjpeg($filename); $type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE'; $colors = imagecolorstotal($gd); imagedestroy($gd); } elseif ($imageSize[2] === IMAGETYPE_GIF) { $gd = imagecreatefromgif($filename); $type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE'; $colors = imagecolorstotal($gd); imagedestroy($gd); } elseif ($imageSize[2] === IMAGETYPE_PNG) { $gd = imagecreatefrompng($filename); $type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE'; $colors = imagecolorstotal($gd); imagedestroy($gd); } $imageInfo->setAnalyzer(get_class($this))->setSize($imageSize[0], $imageSize[1])->setResolution(null, null)->setUnits(null)->setFormat($this->mapFormat($imageSize[2]))->setColors($colors)->setType($type)->setColorspace(!empty($imageSize['channels']) ? $imageSize['channels'] === 4 ? 'CMYK' : 'RGB' : 'RGB')->setDepth($imageSize['bits'])->setCompression(null)->setQuality(null)->setProfiles(null); return $imageInfo; }
/** * {@inheritdoc} */ public function analyze($filename) { $imageInfo = new ImageInfo(); try { $gmagick = new Gmagick($filename); } catch (\Exception $e) { throw new UnsupportedFileException('File type not supported.', 0, $e); } $imageInfo->setAnalyzer(get_class($this))->setSize($gmagick->getImageWidth(), $gmagick->getImageHeight())->setResolution($gmagick->getImageResolution()['x'], $gmagick->getImageResolution()['y'])->setUnits($this->mapUnits($gmagick->getImageUnits()))->setFormat($gmagick->getImageFormat())->setColors($gmagick->getImageColors())->setType($this->mapType($gmagick->getImageType()))->setColorspace($this->mapColorspace($gmagick->getImageColorspace()))->setDepth($gmagick->getImageDepth())->setCompression(null)->setQuality(null); return $imageInfo; }
/** * {@inheritdoc} */ public function analyze($filename) { try { $imagick = new Imagick($filename); } catch (\Exception $e) { throw new UnsupportedFileException('File type not supported.', 0, $e); } $imageInfo = new ImageInfo(); $identify = $imagick->identifyImage(false); $imageInfo->setAnalyzer(get_class($this))->setSize($imagick->getImageWidth(), $imagick->getImageHeight())->setResolution($imagick->getImageResolution()['x'], $imagick->getImageResolution()['y'])->setUnits($this->mapUnits($imagick->getImageUnits()))->setFormat($imagick->getImageFormat())->setColors($imagick->getImageColors())->setType($this->mapType($imagick->getImageType()))->setColorspace($this->mapColorspace($imagick->getImageColorspace()))->setDepth($imagick->getImageDepth())->setCompression($identify['compression'])->setQuality($imagick->getImageCompressionQuality())->setProfiles($imagick->getImageProfiles('*', false)); return $imageInfo; }
public function testConstruct() { $info = new ImageInfo(); $this->assertNull($info->getColors()); }