From f5c1d2ef2e9de3bded7483778618bf8cac2511c3 Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Tue, 12 May 2015 15:56:19 -0700 Subject: [PATCH] Truly detecting the format of images passed in as a string Previously all images were being treated as PNGs --- src/GdThumb.inc.php | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/GdThumb.inc.php b/src/GdThumb.inc.php index fe8edba..a123af2 100644 --- a/src/GdThumb.inc.php +++ b/src/GdThumb.inc.php @@ -96,26 +96,27 @@ public function __construct ($fileName, $options = array(), $isDataStream = fals parent::__construct($fileName, $isDataStream); $this->determineFormat(); + $this->verifyFormatCompatiblity(); if ($this->isDataStream === false) { - $this->verifyFormatCompatiblity(); - } - - switch ($this->format) + switch ($this->format) + { + case 'GIF': + $this->oldImage = imagecreatefromgif($this->fileName); + break; + case 'JPG': + $this->oldImage = imagecreatefromjpeg($this->fileName); + break; + case 'PNG': + $this->oldImage = imagecreatefrompng($this->fileName); + break; + } + } + + else { - case 'GIF': - $this->oldImage = imagecreatefromgif($this->fileName); - break; - case 'JPG': - $this->oldImage = imagecreatefromjpeg($this->fileName); - break; - case 'PNG': - $this->oldImage = imagecreatefrompng($this->fileName); - break; - case 'STRING': - $this->oldImage = imagecreatefromstring($this->fileName); - break; + $this->oldImage = imagecreatefromstring($this->fileName); } $this->currentDimensions = array @@ -1465,7 +1466,9 @@ protected function determineFormat () { if ($this->isDataStream === true) { - $this->format = 'STRING'; + $data = getimagesizefromstring($this->fileName); + $this->format = strtoupper(image_type_to_extension($data[2], false)); + if ($this->format == 'JPEG') $this->format = 'JPG'; return; }