diff options
Diffstat (limited to 'src/PHPImageWorkshop/ImageWorkshop.php')
-rw-r--r-- | src/PHPImageWorkshop/ImageWorkshop.php | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/src/PHPImageWorkshop/ImageWorkshop.php b/src/PHPImageWorkshop/ImageWorkshop.php index 88330f7..914edd0 100644 --- a/src/PHPImageWorkshop/ImageWorkshop.php +++ b/src/PHPImageWorkshop/ImageWorkshop.php @@ -36,7 +36,7 @@ class ImageWorkshop /**
* @var integer
*/
- const ERROR_NOT_WRITABLE_FILE = 3;
+ const ERROR_NOT_READABLE_FILE = 3;
/**
* @var integer
@@ -55,51 +55,50 @@ class ImageWorkshop */
public static function initFromPath($path, $fixOrientation = false)
{
- if (file_exists($path) && !is_dir($path)) {
-
- if (!is_readable($path)) {
- throw new ImageWorkshopException('Can\'t open the file at "'.$path.'" : file is not writable, did you check permissions (755 / 777) ?', static::ERROR_NOT_WRITABLE_FILE);
- }
-
- $imageSizeInfos = @getImageSize($path);
- $mimeContentType = explode('/', $imageSizeInfos['mime']);
-
- if (!$mimeContentType || !array_key_exists(1, $mimeContentType)) {
- throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
- }
-
- $mimeContentType = $mimeContentType[1];
- $exif = array();
-
- switch ($mimeContentType) {
- case 'jpeg':
- $image = imageCreateFromJPEG($path);
- $exif = read_exif_data($path);
- break;
+ if (false === ($imageSizeInfos = @getImageSize($path))) {
+ throw new ImageWorkshopException('Can\'t open the file at "'.$path.'" : file is not readable, did you check permissions (755 / 777) ?', static::ERROR_NOT_READABLE_FILE);
+ }
- case 'gif':
- $image = imageCreateFromGIF($path);
- break;
+ $mimeContentType = explode('/', $imageSizeInfos['mime']);
+ if (!$mimeContentType || !isset($mimeContentType[1])) {
+ throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
+ }
- case 'png':
- $image = imageCreateFromPNG($path);
- break;
+ $mimeContentType = $mimeContentType[1];
+ $exif = array();
- default:
- throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
- break;
- }
+ switch ($mimeContentType) {
+ case 'jpeg':
+ $image = imageCreateFromJPEG($path);
+ if (false === ($exif = @read_exif_data($path))) {
+ $exif = array();
+ }
+ break;
- $layer = new ImageWorkshopLayer($image, $exif);
+ case 'gif':
+ $image = imageCreateFromGIF($path);
+ break;
- if ($fixOrientation) {
- $layer->fixOrientation();
- }
+ case 'png':
+ $image = imageCreateFromPNG($path);
+ break;
- return $layer;
+ default:
+ throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
+ break;
}
-
- throw new ImageWorkshopException('No such file found at "'.$path.'"', static::ERROR_IMAGE_NOT_FOUND);
+
+ if (false === $image) {
+ throw new ImageWorkshopException('Unable to create image with file found at "'.$path.'"');
+ }
+
+ $layer = new ImageWorkshopLayer($image, $exif);
+
+ if ($fixOrientation) {
+ $layer->fixOrientation();
+ }
+
+ return $layer;
}
/**
|