简体   繁体   中英

Sylius liip imagine: Unable to open image

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.

我不知道这是否是您的情况,但如果您使用的是 php7.4,则可能必须按照此处的说明为 jpeg 显式配置 php-gd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM