Elastic Beanstalk 上的 Django Weasyprint - 无法加载 GDK-Pixbuf

标签 django amazon-web-services amazon-elastic-beanstalk weasyprint

我已在 Elastic Beanstalk 上安装了 weasyprint。到目前为止,html 模板的打印工作正常,但我无法打印 svg 图像。

Weasyprint 抛出以下错误:

Failed to load image at "https://myurl/media/X247QAQ2IO.svg" (Could not load GDK-Pixbuf. PNG and SVG are the only image formats available.)

我需要 gdk-pixbuf 来打印 SVG 吗?如果是这样,我如何在 Amazon Linux 上安装它?

Yum does not have gdk-pixbuf2 available for installation

最佳答案

我通过手动构建 gdk-pixbuf2 找到了一个适合我的解决方案,下面的脚本源自 https://gist.github.com/whyvez/1e0212a35da97aa8f1b1他们需要在哪里安装图像魔法

weazy.conf

files:
 "/opt/elasticbeanstalk/hooks/appdeploy/pre/00_instal_weasyprint_prerequisites.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash

      yum install -y libxml2-devel libxslt-devel python-devel redhat-rpm-config libffi-devel cairo pango

      export PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/pkgconfig
      export PATH=/usr/bin:$PATH
      export LDFLAGS=-L/usr/lib64:/usr/lib
      export LD_LIBRARY_PATH=/usr/lib64:/usr/lib
      export CPPFLAGS=-I/usr/include

      sudo yum-config-manager --enable epel
      sudo yum update -y
      sudo yum install -y gcc gcc-c++ glib2-devel.x86_64 libxml2-devel.x86_64 libpng-devel.x86_64 \
      libjpeg-turbo-devel.x86_64 gobject-introspection.x86_64 gobject-introspection-devel.x86_64

      wget http://ftp.gnome.org/pub/GNOME/sources/libcroco/0.6/libcroco-0.6.8.tar.xz
      tar xvfJ libcroco-0.6.8.tar.xz
      cd libcroco-0.6.8
      ./configure --prefix=/usr
      make
      sudo make install
      cd ..

      wget http://ftp.gnome.org/pub/GNOME/sources/gdk-pixbuf/2.28/gdk-pixbuf-2.28.2.tar.xz
      tar xvfJ gdk-pixbuf-2.28.2.tar.xz
      cd gdk-pixbuf-2.28.2
      ./configure --prefix=/usr --without-libtiff
      make
      sudo make install
      cd ..

      sudo yum install -y pixman-devel.x86_64 harfbuzz-devel.x86_64 freetype-devel.x86_64

      wget wget http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.10.91.tar.gz
      tar xvf fontconfig-2.10.91.tar.gz
      cd fontconfig-2.10.91
      ./configure --prefix=/usr --enable-libxml2
      make
      sudo make install
      cd ..

      wget http://cairographics.org/releases/cairo-1.12.14.tar.xz
      tar xvfJ cairo-1.12.14.tar.xz
      cd cairo-1.12.14
      ./configure --prefix=/usr
      make
      sudo make install
      cd ..

      wget http://ftp.gnome.org/pub/GNOME/sources/pango/1.34/pango-1.34.1.tar.xz
      tar xvfJ pango-1.34.1.tar.xz
      cd pango-1.34.1
      ./configure --prefix=/usr
      make
      sudo make install
      cd ..

      wget http://ftp.gnome.org/pub/GNOME/sources/librsvg/2.40/librsvg-2.40.6.tar.xz
      tar xvfJ librsvg-2.40.6.tar.xz
      cd librsvg-2.40.6
      ./configure --prefix=/usr
      make
      sudo make install
      cd ..


      sudo ldconfig /usr/lib

关于Elastic Beanstalk 上的 Django Weasyprint - 无法加载 GDK-Pixbuf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41820538/

相关文章:

django - MongoEngine——如何为身份验证()自定义用户模型/自定义后端

django - 通过 django 信号向用户发送消息

mysql - 两个 Web 服务器之间的 phpMyAdmin 安装

python - 使用 Boto 下载 S3 文件

amazon-web-services - 如何使用已经运行的eb env配置eb cli

python - 在 Django 模板中错误传递带有空格的字符串

amazon-web-services - 如何确保 AWS Cloudformation 更新期间资源删除/创建顺序

python - 删除 aws beanstalk 上的 uuid python 包

amazon-web-services - 如何在由 elastic-beanstalk 创建的 ec2 实例上设置标签

python - 使用 Django 中的通用 View 将请求传递给模型表单