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

Pdf not loading using docker-compose #499

Closed
goelinsights opened this issue Sep 4, 2020 · 2 comments
Closed

Pdf not loading using docker-compose #499

goelinsights opened this issue Sep 4, 2020 · 2 comments

Comments

@goelinsights
Copy link

goelinsights commented Sep 4, 2020

Brief Description

Trying to create derivative (thumbnails) of PDF with a multi-stage docker-compose setup. Getting "VipsForeignLoad: "/tmp/shrine20200904-1-13d7xwu.pdf" is not a known file format"

Expected behavior

Able to use ImageProcessing gem to load PDF and process JPEG thumbnails.

Actual behavior

Error loading the PDF

Traceback (most recent call last):
        2: from (irb):1
        1: from app/uploaders/brochure_uploader.rb:53:in `block in <class:BrochureUploader>'
Vips::Error (VipsForeignLoad: "/tmp/shrine20200904-1-13d7xwu.pdf" is not a known file format)
VipsForeignLoad: "/tmp/shrine20200904-1-13d7xwu.pdf" is not a known file format

Simplest self-contained example code to demonstrate issue

from brochure_uploader.rb
Attacher.derivatives do |original|
    vips = ImageProcessing::Vips.source(original)
    
    starter = vips.loader(page: 0).resize_to_fit(3000, nil).convert("jpeg")
    
 
    # generate the thumbnails you want here 
    { 
      thumb:  starter.saver(quality: 70).resize_to_limit!(150, 225),
      square_300_h: starter.saver(quality: 80).resize_to_fill!(300, 301),
      w_1000_h: starter.saver(quality: 80).resize_to_limit!(1000, nil),
      w_2500_h: starter.saver(quality: 90).resize_to_limit!(2500, nil),
    }
  end

and libraries loaded in the Dockerfile. I had thought that adding poppler would have supplied the necessary PDF file loading support, but it doesn't appear to work

# Stage Final
FROM ruby:2.6.3-alpine
RUN apk add --update --no-cache \
  bash \
  postgresql-client \
  vips \
  poppler-glib \
  tzdata \
  imagemagick \
  jpegoptim

System configuration

Ruby version: 2.6.3

Shrine version: 3.2.2

@janko
Copy link
Member

janko commented Sep 4, 2020

Have you tried loading a PDF directly using ruby-vips? It's most likely not an issue with ImageProcessing gem, but ruby-vips/libvips itself, that it doesn't have PDF support. Personally I don't know what's exactly necessary in order to install libvips with PDF support, you'll have to find that out from the libvips maintainer or their installation guide.

Since this is not an issue with Shrine itself (ImageProcessing is a separate gem), I will close the issue.

@janko janko closed this as completed Sep 4, 2020
@goelinsights
Copy link
Author

goelinsights commented Sep 4, 2020

If anyone comes across this in the future, I figured out that Vips doesn't install the PDF component (poppler) in a docker package and set configuration for PDF. Some licensing issue with GPL. You can either roll your own or use ImageMagick

Here's an example of how you can create a thumbnail jpeg of a PDF using "create_derivatives" in Shrine.

Attacher.derivatives do |original|
    orig = ImageProcessing::ImageMagick.source(original)
    starter = orig.loader(page: 1).convert("jpeg")
    # generate the thumbnails you want here 
    { 
      thumb:  starter.call,
      square_300_h: starter.saver(quality: 80).resize_to_fill!(300, 301),
      w_1000_h: starter.saver(quality: 80).resize_to_fit!(1000, nil)
    }
  end

The output from imagemagick is a bit lower quality than VIPS in my out of the box comparison on my machine, so if anyone figures out the right apt-get packages to get PDF recognition to turn on, would love to hear about it.

Relevant comments here:
libvips/php-vips-ext#31 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants