I've been struggling to do this with Carrierwave. Shrine looks much more flexible, so I've been thinking about switching to Shrine.
How would I go about converting a single PDF into multiple images, with one image per page? The Shrine docs suggest creating a new table for multiple files, but I think that would be overkill in this case. I would like to store an array of images in the metadata, or even just a page count that can be used to generate the URLs.
But I don't know where to go from there.
This is the code I was testing for Carrierwave:
version :jpg do
process :convert_to_images
def convert_to_images(*args)
image = MiniMagick::Image.open(current_path)
image.pages.each_with_index do |page, index|
MiniMagick::Tool::Convert.new do |convert|
convert.background 'white'
convert.flatten
convert.density 300
convert.quality 95
convert << page.path
convert << "#{CarrierWave.root}/#{store_dir}/image-#{index}.jpg"
end
end
end
end
(It doesn't work properly, but it does generate the correct images.)
I've looked at the "versions" plugin, but the documentation states that I need to return a hash of files. I really just want to return an array of generated images, and the page count.
Any help would be greatly appreciated! Also a PDF example would be really helpful in the docs.
Thanks,
Nathan