5

I'm working on a Sylius 1.5 project, everything is working fine on my local environment however when deploying to my dev environment I'm getting an error on filtered images (using liip imagine filters).

The environment consists of a docker php-apache container running sylius. The host machine proxies requests to the docker container.

This is the error I get when I try to load the image's url in my browser:

Unable to create image for path "b4/11/650996cb08ee2b5fef5dfc75b8b4.jpeg" and filter "sylius_shop_product_thumbnail". Message was "Unable to open image /var/www/html/public/media/image/b4/11/650996cb08ee2b5fef5dfc75b8b4.jpeg"

The error occurs here: in vendor/imagine/imagine/lib/Imagine/Gd/Imagine.php (line 96)

Observations:

  • Image path is good
  • Image exists on file system
  • PHP manages to read the data from the file with file_get_contents
  • imagecreatefromstring doesn't manage to create resource from data

Here is the code where the error occurs:

    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));
    }

I've tried dumping the variables, and it seems imagine succeeds in getting the data from the file with file_get_contents, however imagecreatefromstring fails.

Here is the apache configuration:

NameVirtualHost 127.0.0.1:8000

Listen 127.0.0.1:8000
LimitRequestBody 10485760

<VirtualHost 127.0.0.1:8000>
  ProxyPreserveHost On
  DocumentRoot "/var/www/html"
  DirectoryIndex index.php
  <Directory "/var/www/html">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Nginx configuration:

server {
        listen 80;
        client_max_body_size 10M;
        server_name mydomain.com;

        location / {
                proxy_pass http://127.0.0.1:8092;
                include /etc/nginx/proxy_params;
        }

}

I'm having trouble figuring out what in the configuration is making this go wrong.

J Dubuis
  • 442
  • 4
  • 11
  • I bypassed the issue by using imagick as liip imagine's driver. It doesn't solve this strange issue but it might help others. – J Dubuis Aug 14 '19 at 10:02

1 Answers1

3

I don't know if this is your case but if you are using php7.4 you might have to configure php-gd explicitly for jpeg as explained here

Dennis de Best
  • 792
  • 6
  • 27