isMemImage = true; } else { $this->isMemImage = (filter_var($source, \FILTER_VALIDATE_URL) !== false); } // Check supported types if ($this->isMemImage) { $supportedTypes = array('image/jpeg', 'image/gif', 'image/png'); $imgData = @getimagesize($source); if (!is_array($imgData)) { throw new InvalidImageException(); } $this->imageType = $imgData['mime']; // string if (!in_array($this->imageType, $supportedTypes)) { throw new UnsupportedImageTypeException(); } } else { $supportedTypes = array( \IMAGETYPE_JPEG, \IMAGETYPE_GIF, \IMAGETYPE_PNG, \IMAGETYPE_BMP, \IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM ); if (!file_exists($source)) { throw new InvalidImageException(); } $imgData = getimagesize($source); if (function_exists('exif_imagetype')) { $this->imageType = exif_imagetype($source); } else { // @codeCoverageIgnoreStart $tmp = getimagesize($source); $this->imageType = $tmp[2]; // @codeCoverageIgnoreEnd } if (!in_array($this->imageType, $supportedTypes)) { throw new UnsupportedImageTypeException(); } $this->imageType = \image_type_to_mime_type($this->imageType); } // Set private properties $this->source = $source; $this->isWatermark = $isWatermark; $this->style = $this->setStyle(new ImageStyle(), $style, true); if ($this->style->getWidth() == null && $this->style->getHeight() == null) { $this->style->setWidth($imgData[0]); $this->style->setHeight($imgData[1]); } $this->setImageFunctions(); } /** * Get Image style * * @return ImageStyle */ public function getStyle() { return $this->style; } /** * Get image source * * @return string */ public function getSource() { return $this->source; } /** * Get image media ID * * @return string */ public function getMediaId() { return md5($this->source); } /** * Get is watermark * * @return boolean */ public function getIsWatermark() { return $this->isWatermark; } /** * Set is watermark * * @param boolean $pValue */ public function setIsWatermark($pValue) { $this->isWatermark = $pValue; } /** * Get image type * * @return string */ public function getImageType() { return $this->imageType; } /** * Get image create function * * @return string */ public function getImageCreateFunction() { return $this->imageCreateFunc; } /** * Get image function * * @return string */ public function getImageFunction() { return $this->imageFunc; } /** * Get image extension * * @return string */ public function getImageExtension() { return $this->imageExtension; } /** * Get is memory image * * @return boolean */ public function getIsMemImage() { return $this->isMemImage; } /** * Set image functions */ private function setImageFunctions() { switch ($this->imageType) { case 'image/png': $this->imageCreateFunc = 'imagecreatefrompng'; $this->imageFunc = 'imagepng'; $this->imageExtension = 'png'; break; case 'image/gif': $this->imageCreateFunc = 'imagecreatefromgif'; $this->imageFunc = 'imagegif'; $this->imageExtension = 'gif'; break; case 'image/jpeg': case 'image/jpg': $this->imageCreateFunc = 'imagecreatefromjpeg'; $this->imageFunc = 'imagejpeg'; $this->imageExtension = 'jpg'; break; case 'image/x-ms-bmp': case 'image/bmp': $this->imageType = 'image/bmp'; $this->imageExtension = 'bmp'; break; case 'image/tiff': $this->imageExtension = 'tif'; break; } } }