jnicklas/carrierwave — Issue #517: Cannot convert multipage PDFs to JPG with RMagick
Author: chanind
Created: 2011-11-05 01:55:40+00:00
State: open

When using process :convert => 'jpg' on a multipage PDF carrierwave throws a LocaJumpError. The reason is that convert calls manipulate!, but does not pass in a block.

A possible solution is to replace the current manipulate! method under / lib / carrierwave / processing / rmagick.rb with the following:

```ruby
def manipulate!(options={})
cache_stored_file! if !cached?
image = ::Magick::Image.read(current_path)

frames = if image.size > 1
list = ::Magick::ImageList.new
image.each do |frame|
list << block_given? ? yield( frame ) : frame
end
block_given? ? list : list.append(true)
else
frame = image.first
frame = yield( frame ) if block_given?
frame
end

if options[:format]
frames.write("#{options[:format]}:#{current_path}")
else
frames.write(current_path)
end
destroy_image(frames)
rescue ::Magick::ImageMagickError => e
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e)
end
```

This turns the multipage image into a single page image if no block is provided. Not sure if this is the best solution though as I think multilayer images will not convert properly using this approach (in theory they're just throwing an error on convert though anway...)