mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-10 01:56:52 +02:00
improving error handling when opening (non)-recoverable images
This commit is contained in:
37
CImage.php
37
CImage.php
@@ -788,6 +788,37 @@ class CImage
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Error message when failing to load somehow corrupt image.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public function failedToLoad()
|
||||
{
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
echo("Fatal error when opening image.<br>");
|
||||
|
||||
switch ($this->fileExtension) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
$this->image = imagecreatefromjpeg($this->pathToImage);
|
||||
break;
|
||||
|
||||
case 'gif':
|
||||
$this->image = imagecreatefromgif($this->pathToImage);
|
||||
break;
|
||||
|
||||
case 'png':
|
||||
$this->image = imagecreatefrompng($this->pathToImage);
|
||||
break;
|
||||
}
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load image from disk.
|
||||
*
|
||||
@@ -809,17 +840,17 @@ class CImage
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
$this->image = @imagecreatefromjpeg($this->pathToImage);
|
||||
$this->image or die("Fatal error when opening image.");
|
||||
$this->image or failedToLoad();
|
||||
break;
|
||||
|
||||
case 'gif':
|
||||
$this->image = @imagecreatefromgif($this->pathToImage);
|
||||
$this->image or die("Fatal error when opening image.");
|
||||
$this->image or failedToLoad();
|
||||
break;
|
||||
|
||||
case 'png':
|
||||
$this->image = @imagecreatefrompng($this->pathToImage);
|
||||
$this->image or die("Fatal error when opening image.");
|
||||
$this->image or failedToLoad();
|
||||
|
||||
$type = $this->getPngType();
|
||||
$hasFewColors = imagecolorstotal($this->image);
|
||||
|
Reference in New Issue
Block a user