Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Only fetch the width and height when it is a file #116

Merged
merged 3 commits into from
Mar 27, 2017
Merged

Conversation

laoneo
Copy link
Contributor

@laoneo laoneo commented Mar 25, 2017

When error reporting is set to maximum, then an error is thrown because the image size can't be determined on a folder. This pr fixes that.

The error is:
Notice: getimagesize(): Read error! in /mm/libraries/vendor/joomla/image/src/Image.php on line 215

@laoneo laoneo added the bug label Mar 25, 2017
@laoneo laoneo added this to the Milestone 1 milestone Mar 25, 2017
@laoneo laoneo self-assigned this Mar 25, 2017
@laoneo laoneo added this to Pull Requests in Controller like Rest endpoints Mar 25, 2017
@laoneo laoneo changed the title Only determine the with and height when it is a file Only fetch the with and height when it is a file Mar 25, 2017
$props = JImage::getImageFileProperties($path);
$obj->width = $props->width;
$obj->height = $props->height;
}
Copy link
Contributor

@dneukirchen dneukirchen Mar 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fix the error for directories but what happens in case of non-image files like html, mp4, pdf? Perhaps we need an isImage() check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most information you find on the net do say that getimagesize is the function to check if it is an image or not. That is what the JImage lib is doing. I'm not sure if it would be enough to rely on the filetyope or mime type only.

@laoneo
Copy link
Contributor Author

laoneo commented Mar 25, 2017

Then an exception is thrown, which we catch.

@dneukirchen
Copy link
Contributor

dneukirchen commented Mar 26, 2017

Hm, is that what we want? Imho exceptions should be thrown (and catched) only in case of serious errors (when the app is unable to recover) and not as part of an expected and valid application flow.

@laoneo laoneo changed the title Only fetch the with and height when it is a file Only fetch the width and height when it is a file Mar 27, 2017

try
if (strpos($obj->mime_type, 'image/') === 0 && in_array(strtolower($obj->extension), array('jpg', 'jpeg', 'png', 'gif', 'bmp')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this in an isImage method to be more readable?

{
// Get the image properties
$props = JImage::getImageFileProperties($path);
$obj->width = $props->width;
$obj->height = $props->height;
}
catch (Exception $e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of exception do we catch here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'v removed that and opened issue #117 as we don't have a defined way of exception handling.

@dneukirchen dneukirchen merged commit ced4729 into milestone1 Mar 27, 2017
@dneukirchen dneukirchen deleted the fix/error branch March 27, 2017 14:00
@dneukirchen
Copy link
Contributor

thanks @laoneo

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants