Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filemanager crashes because Image has recognized format #1116

Closed
ghost opened this issue Sep 28, 2017 · 5 comments
Closed

Filemanager crashes because Image has recognized format #1116

ghost opened this issue Sep 28, 2017 · 5 comments
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Sep 28, 2017

Issue by @biwerr
September 28th, 2017, 16:13 GMT

Filemanager fails if there are problems with Imageresizing. I've uplaoded serveral images via FTP. After that Contao Filemanager throws an RuntimeException with missleading Exception Message "Unable to open image".

The real Problem was "Warning: imagecreatefromstring(): Data is not in a recognized format" in Imagine Library which was return by the function imagecreatefromstring

 public function open($path)
    {
        $path = $this->checkPath($path);
        $data = @file_get_contents($path);

        if (false === $data) {
            throw new RuntimeException(sprintf('Failed to open file %s', $path));
        }

        $resource = @imagecreatefromstring($data);
        
        
        if (!is_resource($resource)) {
            throw new RuntimeException(sprintf('Unable to open image %s', $path));
        }

        return $this->wrap($resource, new RGB(), $this->getMetadataReader()->readFile($path));
    }

Trace:

Symfony\Component\Debug\Exception\ContextErrorException:
Warning: imagecreatefromstring(): Data is not in a recognized format

  at vendor/imagine/imagine/lib/Imagine/Gd/Imagine.php:93
  at Imagine\Gd\Imagine->open('/kunden/384317_80538/cms/files/claus-vogt/images/Grundsatzvideo Schuldenkrise_257.jpg')
     (vendor/contao/image/src/Resizer.php:131)
  at Contao\Image\Resizer->executeResize(object(Image), object(ResizeCoordinates), '/kunden/384317_80538/cms/assets/images/e/Grundsatzvideo Schuldenkrise_257-9cf1e71e.jpg', object(ResizeOptions))
     (vendor/contao/core-bundle/src/Image/LegacyResizer.php:138)
  at Contao\CoreBundle\Image\LegacyResizer->executeResize(object(Image), object(ResizeCoordinates), 

Maybe a fix could be wrapping executeResize in try catch block the prevent Contao Filemanager from crashing

@leofeyer
Copy link
Member

leofeyer commented Oct 9, 2017

Maybe a fix could be wrapping executeResize in try catch block the prevent Contao Filemanager from crashing

@ausi Is this suited to fix the problem?

@ausi
Copy link
Member

ausi commented Oct 9, 2017

Is this suited to fix the problem?

Yes, I think it is.

We should probably catch all exceptions that implement the Imagine\Exception\Exception interface and show a “broken image” icon instead of the thumbnail, so that the user can see that there is something wrong with the image.

@leofeyer
Copy link
Member

I failed to reproduce the issue with an image I broke myself. @biwerr Can you please provide an example image?

@leofeyer
Copy link
Member

@ausi pointed out that $objFile->isImage && $objFile->viewHeight > 0 needs to be true so Contao tries to create a preview image. However, broken images do not have a height, so I wonder how you managed to have a broken image with a height. 😄

@leofeyer
Copy link
Member

Fixed in c755176.

@leofeyer leofeyer modified the milestones: 4.4.7, 4.4 May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants