From d0965060bcbc5d1a6c3655c66fc79b970873be49 Mon Sep 17 00:00:00 2001 From: liaofei <136327134@qq.com> Date: Fri, 24 Feb 2023 18:03:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=95=E5=B1=82=E4=B8=8D?= =?UTF-8?q?=E5=85=BC=E5=AE=B9fileinfo=E6=89=A9=E5=B1=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Intervention/Image/AbstractDecoder.php | 42 +++++++++---------- .../image/src/Intervention/Image/File.php | 6 +-- .../src/Intervention/Image/Gd/Decoder.php | 2 +- .../src/Intervention/Image/ImageManager.php | 10 ++--- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/crmeb/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php b/crmeb/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php index e51d4da3c..513813c0d 100644 --- a/crmeb/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php +++ b/crmeb/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php @@ -11,7 +11,7 @@ abstract class AbstractDecoder /** * Initiates new image from path in filesystem * - * @param string $path + * @param string $path * @return \Intervention\Image\Image */ abstract public function initFromPath($path); @@ -19,7 +19,7 @@ abstract class AbstractDecoder /** * Initiates new image from binary data * - * @param string $data + * @param string $data * @return \Intervention\Image\Image */ abstract public function initFromBinary($data); @@ -27,7 +27,7 @@ abstract class AbstractDecoder /** * Initiates new image from GD resource * - * @param Resource $resource + * @param Resource $resource * @return \Intervention\Image\Image */ abstract public function initFromGdResource($resource); @@ -60,30 +60,30 @@ abstract class AbstractDecoder /** * Init from given URL * - * @param string $url + * @param string $url * @return \Intervention\Image\Image */ public function initFromUrl($url) { - + $options = [ 'http' => [ - 'method'=>"GET", - 'protocol_version'=>1.1, // force use HTTP 1.1 for service mesh environment with envoy - 'header'=>"Accept-language: en\r\n". - "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36\r\n" - ] + 'method' => "GET", + 'protocol_version' => 1.1, // force use HTTP 1.1 for service mesh environment with envoy + 'header' => "Accept-language: en\r\n" . + "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36\r\n" + ] ]; - - $context = stream_context_create($options); - + + $context = stream_context_create($options); + if ($data = @file_get_contents($url, false, $context)) { return $this->initFromBinary($data); } throw new NotReadableException( - "Unable to init from given url (".$url.")." + "Unable to init from given url (" . $url . ")." ); } @@ -213,7 +213,7 @@ abstract class AbstractDecoder */ public function isUrl() { - return (bool) filter_var($this->data, FILTER_VALIDATE_URL); + return (bool)filter_var($this->data, FILTER_VALIDATE_URL); } /** @@ -238,8 +238,8 @@ abstract class AbstractDecoder public function isBinary() { if (is_string($this->data)) { - $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $this->data); - return (substr($mime, 0, 4) != 'text' && $mime != 'application/x-empty'); + $mime = getimagesize($this->data)['mime'] ?? ''; + return !in_array($mime, ['image/jpeg', 'image/png', 'image/gif']); } return false; @@ -274,7 +274,7 @@ abstract class AbstractDecoder /** * Initiates new Image from Intervention\Image\Image * - * @param Image $object + * @param Image $object * @return \Intervention\Image\Image */ public function initFromInterventionImage($object) @@ -285,7 +285,7 @@ abstract class AbstractDecoder /** * Parses and decodes binary image data from data-url * - * @param string $data_url + * @param string $data_url * @return string */ private function decodeDataUrl($data_url) @@ -307,7 +307,7 @@ abstract class AbstractDecoder /** * Initiates new image from mixed data * - * @param mixed $data + * @param mixed $data * @return \Intervention\Image\Image */ public function init($data) @@ -359,6 +359,6 @@ abstract class AbstractDecoder */ public function __toString() { - return (string) $this->data; + return (string)$this->data; } } diff --git a/crmeb/vendor/intervention/image/src/Intervention/Image/File.php b/crmeb/vendor/intervention/image/src/Intervention/Image/File.php index cf15da0bf..1036dbae9 100644 --- a/crmeb/vendor/intervention/image/src/Intervention/Image/File.php +++ b/crmeb/vendor/intervention/image/src/Intervention/Image/File.php @@ -53,7 +53,7 @@ class File $this->filename = array_key_exists('filename', $info) ? $info['filename'] : null; if (file_exists($path) && is_file($path)) { - $this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); + $this->mime = getimagesize($path)['mime'] ?? ''; } return $this; @@ -61,7 +61,7 @@ class File /** * Get file size - * + * * @return mixed */ public function filesize() @@ -71,7 +71,7 @@ class File if (file_exists($path) && is_file($path)) { return filesize($path); } - + return false; } diff --git a/crmeb/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php b/crmeb/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php index f5c34aa50..c0cb7dac1 100644 --- a/crmeb/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php +++ b/crmeb/vendor/intervention/image/src/Intervention/Image/Gd/Decoder.php @@ -23,7 +23,7 @@ class Decoder extends \Intervention\Image\AbstractDecoder } // get mime type of file - $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); + $mime = getimagesize($path)['mime'] ?? ''; // define core switch (strtolower($mime)) { diff --git a/crmeb/vendor/intervention/image/src/Intervention/Image/ImageManager.php b/crmeb/vendor/intervention/image/src/Intervention/Image/ImageManager.php index 324fe7fa3..794c23ead 100644 --- a/crmeb/vendor/intervention/image/src/Intervention/Image/ImageManager.php +++ b/crmeb/vendor/intervention/image/src/Intervention/Image/ImageManager.php @@ -133,10 +133,10 @@ class ImageManager */ private function checkRequirements() { - if ( ! function_exists('finfo_buffer')) { - throw new MissingDependencyException( - "PHP Fileinfo extension must be installed/enabled to use Intervention Image." - ); - } +// if ( ! function_exists('finfo_buffer')) { +// throw new MissingDependencyException( +// "PHP Fileinfo extension must be installed/enabled to use Intervention Image." +// ); +// } } }