1
votes

When i'm running convert via command line

convert -verbose -density 300 -trim -quality 100 1565_002.pdf test_image.png

the result is good. Verbose showing output:

"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r400x400" "-sOutputFile=/var/tmp/magick-39357qEey9jeURtmJ%d" "-f/var/tmp/magick-39357DTf85TEO2pfX" "-f/var/tmp/magick-39357aIeGxsC4sZlD" /var/tmp/magick-39357qEey9jeURtmJ1 PNG 3400x4400 3400x4400+0+0 8-bit sRGB 144KB 0.300u 0:00.289

1565_002.pdf PNG 3400x4400 3400x4400+0+0 16-bit sRGB 144KB 0.000u 0:00.000

1565_002.pdf=>test_image.png PNG 3400x4400=>2778x3582 3400x4400+311+233 8-bit sRGB 2c 39.4KB 0.410u 0:00.420

BUT when uploading pdf via rails

  has_attached_file :photo,
                # ...storage options...
                :styles => { :pdf_thumbnail => ["", :png] },
                :convert_options => { 
                  :all => '-auto-orient',
                  :pdf_thumbnail => "-verbose -density 300 -trim -quality 100"
                }  

The result is VERY poor.

Rails (paperclip) + Verbose output:

Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey.pdf[0]'

Command :: convert '/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey.pdf[0]' -auto-orient -verbose -density 300 -trim -quality 100 -auto-orient '/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey20150206-39272-1qf97j3.png'

/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey.pdf[0]=>/var/folders/3d/td4xb1s56wxb1tcrl8rgy6tw0000gn/T/1565_00220150206-39272-wftjey20150206-39272-1qf97j3.png PNG 612x792=>500x645 612x792+56+42 8-bit sRGB 2c 4.06KB 0.010u 0:00.020

The problem is here - "PNG 612x792=>500x645 612x792+56+42" instead of "PNG 3400x4400 3400x4400+0+0".

So how this could be fixed? Or what option should i add.

I'm using rails (4.0.2), paperclip (3.5.2), rmagick (2.13.4)

1

1 Answers

0
votes

Finally, i tried these solution - https://gist.github.com/bastien/3059321

There additional ghostscript setup which transform pdf with more deeper pixel per inch value (originally was r144 and i've changed it to r400) and other custom options.