php Sylius liip想象一下:无法打开图像

r3i60tvu  于 2023-05-21  发布在  PHP
关注(0)|答案(2)|浏览(150)

我正在做一个Sylius 1.5项目,在我的本地环境中一切都很好,但是当部署到我的开发环境中时,我在过滤的图像上得到了一个错误(使用liip imagine过滤器)。
环境由一个运行sylius的docker php-apache容器组成。主机将请求代理到docker容器。
这是当我尝试在浏览器中加载图像的URL时得到的错误:

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"

错误发生在这里:in vendor/imagine/imagine/lib/Imagine/Gd/Imagine.php (line 96)
观察结果:

  • 图像路径良好
  • 文件系统上存在映像
  • PHP使用file_get_contents从文件中读取数据
  • 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));
    }

我已经尝试转储变量,似乎imagine成功地从file_get_contents文件中获取数据,但是imagecreatefromstring失败了。
下面是Apache配置:

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配置:

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

}

我搞不清楚配置中的什么东西会出错。

hujrc8aj

hujrc8aj1#

我不知道这是否是你的情况,但如果你使用的是php7.4,你可能需要像here解释的那样为jpeg显式配置php-gd

yfwxisqw

yfwxisqw2#

我解决了这个问题你需要安装jpg和png库和配置GD

# setup GD extension
RUN apt-get update && \
apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev && \
docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ && \
docker-php-ext-install gd

相关问题