You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've managed to get PDF conversion of the first page to an image to work with the following in process.
require"image_processing/mini_magick"classImageUploader < ShrineMAX_IMAGE_SIZE_MB=50includeImageProcessing::MiniMagickplugin:determine_mime_typeplugin:remove_attachmentplugin:store_dimensionsplugin:validation_helpersplugin:versions,names: [:original,:thumb,:large]plugin(:default_url){ |_| '/img/preview-not-available.jpg'}Attacher.validatedovalidate_max_sizeMAX_IMAGE_SIZE_MB.megabytes,message: "is too large (max is #{MAX_IMAGE_SIZE_MB} MB)"validate_mime_type_inclusion['image/jpeg','image/png','image/gif','application/pdf']enddefprocess(io,context)casecontext[:phase]when:storeifio.mime_type == 'application/pdf'# NOTE: `convert!` calls `format` which defaults to copying page 0 onlypng_file=convert!(io.download,"png")thumb=resize_to_limit(png_file,200,200)elsethumb=resize_to_limit!(large,200,200)end{original: io,thumb: thumb}endendend
However, for a relatively larger PDF (600+ pages), this code is timing out on Rails after about 1 minute. Attempting imagemagick manually on the command line works in about 1-2 seconds.
Aha, I think I know where the problem is here. You want to convert only the first page of the PDF, correct? The default behaviour of image_processing is that it converts all the pages. This behaviour is probably strange, especially because MiniMagick's default is that it only converts the first page (the page "0"), so this default behaviour will likely change in the near future (to MiniMagick's).
I've just pushed to image_processing the ability to supply the page number, so if you pull from master you can rewrite it with:
png_file=convert!(io.download,"png",0)
Alternatively, if you would rather keep the RubyGems version of image_processing, you can write:
Ah, I fell for the old "the default of my friend is not the default I give my friend" trap, haha. Yes, I agree that sticking to the first page is a nicer default. For now I'll stick to the RubyGems version code above (which works great). Thanks!
I've managed to get PDF conversion of the first page to an image to work with the following in
process
.However, for a relatively larger PDF (600+ pages), this code is timing out on Rails after about 1 minute. Attempting imagemagick manually on the command line works in about 1-2 seconds.
$ convert "emacs.pdf[0]" emacs.png
Am I doing something wrong?
Related to #52 in that it's the same scenario.
PDF: https://www.gnu.org/software/emacs/manual/pdf/emacs.pdf
The text was updated successfully, but these errors were encountered: