/** * Get meta data of image or base64 string * * @param null|string $image * @param bool|null $strict * * @return $this * @throws Exception */ protected function _loadMeta($image = null, $strict = false) { // Gather meta data if (null === $image && $this->_filename) { $imageInfo = getimagesize($this->_filename); $this->_image = $this->_imageCreate($imageInfo['mime']); } elseif (Helper::isGdRes($image)) { $this->_image = $image; $imageInfo = array('0' => imagesx($this->_image), '1' => imagesy($this->_image), 'mime' => 'image/png'); } else { if (!Sys::isFunc('getimagesizefromstring')) { throw new Exception('PHP 5.4 is required to use method getimagesizefromstring'); } if ($strict) { $cleanedString = str_replace(' ', '+', preg_replace('#^data:image/[^;]+;base64,#', '', $image)); if (base64_decode($cleanedString, true) === false) { throw new Exception('Invalid image source.'); } } $image = Helper::strToBin($image); $imageInfo = getimagesizefromstring($image); $this->_image = imagecreatefromstring($image); } // Set internal state $this->_mime = $imageInfo['mime']; $this->_width = $imageInfo['0']; $this->_height = $imageInfo['1']; $this->_exif = $this->_getExif(); $this->_orient = $this->_getOrientation(); // Prepare alpha chanel Helper::addAlpha($this->_image); return $this; }
/** * Get meta data of image or base64 string * * @param null|string $image * * @return $this * @throws Exception */ protected function _loadMeta($image = null) { // Gather meta data if (null === $image && $this->_filename) { $imageInfo = getimagesize($this->_filename); $this->_image = $this->_imageCreate($imageInfo['mime']); } elseif (Helper::isGdRes($image)) { $this->_image = $image; $imageInfo = array('0' => imagesx($this->_image), '1' => imagesy($this->_image), 'mime' => 'image/png'); } else { if (!Sys::isFunc('getimagesizefromstring')) { throw new Exception('PHP 5.4 is required to use method getimagesizefromstring'); } $image = Helper::strToBin($image); $imageInfo = getimagesizefromstring($image); $this->_image = imagecreatefromstring($image); } // Set internal state $this->_mime = $imageInfo['mime']; $this->_width = $imageInfo['0']; $this->_height = $imageInfo['1']; $this->_exif = $this->_getExif(); $this->_orient = $this->_getOrientation(); // Prepare alpha chanel Helper::addAlpha($this->_image); return $this; }