Fix for 500 - ISE, when the uploaded file extension does not match file encoding
This commit is contained in:
parent
b7c5ced470
commit
59e3392fde
1 changed files with 14 additions and 11 deletions
|
@ -5,17 +5,13 @@ class Image {
|
||||||
private $image;
|
private $image;
|
||||||
private $width;
|
private $width;
|
||||||
private $height;
|
private $height;
|
||||||
|
private $type;
|
||||||
private $imageResized;
|
private $imageResized;
|
||||||
|
|
||||||
public function setImage($fileName, $newWidth, $newHeight, $option="auto")
|
public function setImage($fileName, $newWidth, $newHeight, $option="auto")
|
||||||
{
|
{
|
||||||
// *** Open up the file
|
// *** Open up the file and resize image
|
||||||
$this->image = $this->openImage($fileName);
|
$this->image = $this->openImage($fileName);
|
||||||
|
|
||||||
// *** Get width and height
|
|
||||||
$this->width = imagesx($this->image);
|
|
||||||
$this->height = imagesy($this->image);
|
|
||||||
|
|
||||||
$this->resizeImage($newWidth, $newHeight, $option);
|
$this->resizeImage($newWidth, $newHeight, $option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,16 +72,23 @@ class Image {
|
||||||
// *** Get extension
|
// *** Get extension
|
||||||
$extension = strtolower(strrchr($file, '.'));
|
$extension = strtolower(strrchr($file, '.'));
|
||||||
|
|
||||||
switch($extension)
|
// *** Get image information (width, height, and type)
|
||||||
|
$info = getimagesize($file);
|
||||||
|
if($info === false) return(false);
|
||||||
|
|
||||||
|
$this->width = $info[0];
|
||||||
|
$this->height = $info[1];
|
||||||
|
$this->type = $info[2];
|
||||||
|
|
||||||
|
switch($this->type)
|
||||||
{
|
{
|
||||||
case '.jpg':
|
case IMAGETYPE_JPEG:
|
||||||
case '.jpeg':
|
|
||||||
$img = imagecreatefromjpeg($file);
|
$img = imagecreatefromjpeg($file);
|
||||||
break;
|
break;
|
||||||
case '.gif':
|
case IMAGETYPE_GIF:
|
||||||
$img = imagecreatefromgif($file);
|
$img = imagecreatefromgif($file);
|
||||||
break;
|
break;
|
||||||
case '.png':
|
case IMAGETYPE_PNG:
|
||||||
$img = imagecreatefrompng($file);
|
$img = imagecreatefrompng($file);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Reference in a new issue