X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FImage.php;h=5cef75180bdb2949f4fac96c903a07bb81d28342;hb=e3692c01053d4714292449d1170ef2d60ad575d7;hp=535eae0b33b8d845d52a506dbc086328a6a32a17;hpb=2c56d2f3360c08e312e5c167261af8e5d4b87af4;p=friendica.git diff --git a/src/Object/Image.php b/src/Object/Image.php index 535eae0b33..5cef75180b 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -1,6 +1,6 @@ image->setFormat($format); // Always coalesce, if it is not a multi-frame image it won't hurt anyway - $this->image = $this->image->coalesceImages(); + try { + $this->image = $this->image->coalesceImages(); + } catch (Exception $e) { + return false; + } /* * setup the compression here, so we'll do it only once @@ -131,9 +134,6 @@ class Image switch ($this->getType()) { case "image/png": $quality = DI::config()->get('system', 'png_quality'); - if ((! $quality) || ($quality > 9)) { - $quality = PNG_QUALITY; - } /* * From http://www.imagemagick.org/script/command-line-options.php#quality: * @@ -147,9 +147,6 @@ class Image break; case "image/jpeg": $quality = DI::config()->get('system', 'jpeg_quality'); - if ((! $quality) || ($quality > 100)) { - $quality = JPEG_QUALITY; - } $this->image->setCompressionQuality($quality); } @@ -227,9 +224,13 @@ class Image } if ($this->isImagick()) { - /* Clean it */ - $this->image = $this->image->deconstructImages(); - return $this->image; + try { + /* Clean it */ + $this->image = $this->image->deconstructImages(); + return $this->image; + } catch (Exception $e) { + return false; + } } return $this->image; } @@ -456,7 +457,6 @@ class Image break; } - // Logger::log('exif: ' . print_r($exif,true)); return $exif; } @@ -539,7 +539,12 @@ class Image do { // FIXME - implement horizontal bias for scaling as in following GD functions // to allow very tall images to be constrained only horizontally. - $this->image->scaleImage($dest_width, $dest_height); + try { + $this->image->scaleImage($dest_width, $dest_height); + } catch (Exception $e) { + // Imagick couldn't use the data + return false; + } } while ($this->image->nextImage()); // These may not be necessary anymore @@ -568,6 +573,21 @@ class Image return true; } + /** + * Convert a GIF to a PNG to make it static + */ + public function toStatic() + { + if ($this->type != 'image/gif') { + return; + } + + if ($this->isImagick()) { + $this->type == 'image/png'; + $this->image->setFormat('png'); + } + } + /** * @param integer $max maximum * @param integer $x x coordinate @@ -611,24 +631,6 @@ class Image $this->height = imagesy($this->image); } - /** - * @param string $path file path - * @return mixed - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - */ - public function saveToFilePath($path) - { - if (!$this->isValid()) { - return false; - } - - $string = $this->asString(); - - $stamp1 = microtime(true); - file_put_contents($path, $string); - DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); - } - /** * Magic method allowing string casting of an Image object * @@ -654,10 +656,14 @@ class Image } if ($this->isImagick()) { - /* Clean it */ - $this->image = $this->image->deconstructImages(); - $string = $this->image->getImagesBlob(); - return $string; + try { + /* Clean it */ + $this->image = $this->image->deconstructImages(); + $string = $this->image->getImagesBlob(); + return $string; + } catch (Exception $e) { + return false; + } } ob_start(); @@ -668,16 +674,10 @@ class Image switch ($this->getType()) { case "image/png": $quality = DI::config()->get('system', 'png_quality'); - if ((!$quality) || ($quality > 9)) { - $quality = PNG_QUALITY; - } imagepng($this->image, null, $quality); break; case "image/jpeg": $quality = DI::config()->get('system', 'jpeg_quality'); - if ((!$quality) || ($quality > 100)) { - $quality = JPEG_QUALITY; - } imagejpeg($this->image, null, $quality); } $string = ob_get_contents(); @@ -685,65 +685,4 @@ class Image return $string; } - - /** - * supported mimetypes and corresponding file extensions - * - * @return array - * @deprecated in version 2019.12 please use Util\Images::supportedTypes() instead. - */ - public static function supportedTypes() - { - return Images::supportedTypes(); - } - - /** - * Maps Mime types to Imagick formats - * - * @return array With with image formats (mime type as key) - * @deprecated in version 2019.12 please use Util\Images::getFormatsMap() instead. - */ - public static function getFormatsMap() - { - return Images::getFormatsMap(); - } - - /** - * Guess image mimetype from filename or from Content-Type header - * - * @param string $filename Image filename - * @param boolean $fromcurl Check Content-Type header from curl request - * @param string $header passed headers to take into account - * - * @return string|null - * @throws Exception - * @deprecated in version 2019.12 please use Util\Images::guessType() instead. - */ - public static function guessType($filename, $fromcurl = false, $header = '') - { - return Images::guessType($filename, $fromcurl, $header); - } - - /** - * @param string $url url - * @return array - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - * @deprecated in version 2019.12 please use Util\Images::getInfoFromURLCached() instead. - */ - public static function getInfoFromURL($url) - { - return Images::getInfoFromURLCached($url); - } - - /** - * @param integer $width width - * @param integer $height height - * @param integer $max max - * @return array - * @deprecated in version 2019.12 please use Util\Images::getScalingDimensions() instead. - */ - public static function getScalingDimensions($width, $height, $max) - { - return Images::getScalingDimensions($width, $height, $max); - } }