Skip to content

Commit

Permalink
Truly detecting the format of images passed in as a string
Browse files Browse the repository at this point in the history
Previously all images were being treated as PNGs
  • Loading branch information
weotch committed May 12, 2015
1 parent 316a472 commit f5c1d2e
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/GdThumb.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f5c1d2e

Please sign in to comment.