I could encode images to Progressive JPEG doing the following thing to my CarrierWave Uploader:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process :optimize #For the real image
version :version_1 do
# other processes
process :optimize
end
version :version_2, from_version: :version_1 do
# other processes
process :optimize
end
version :version_3, from_version: :version_2 do
# other processes
process :optimize
end
def optimize
manipulate! do |img|
img.combine_options do |c|
c.strip
c.quality '100'
c.depth '8'
c.interlace 'Line'
end
img
end
end
end
You have to put last the process that converts the image to Progressive JPEG otherwise it won't be converted.
Then if you already have uploaded some images and you want to "re-create" them.
Imagine that your model is:
class Picture < ActiveRecord::Base
mount_uploader :image, ImageUploader
end
So you have to do the following to recreate the versions:
Picture.order("id ASC").each do |p|
p.image.recreate_versions!
puts "#{p.id}, #{p.image.url}"
end
I ordered the picture based on the ID because if it fails in the middle of the process I have the ID and I can continue from that ID. Another thing you can do is to rescue any exception, and save in an array the pictures that fails, something like this:
errored = []
Picture.order("id ASC").each do |p|
begin
p.image.recreate_versions!
rescue => e
errored << p.id
end
puts "#{p.id}, #{p.image.url}"
end
Finally, to check that the image was converted to Progressive JPEG, having ImageMagick installed, type the following in the terminal:
identify -verbose PATH_TO_IMAGE | grep Interlace
If the image is Progressive JPEG, the output will be Interlace: JPEG
, if not Interlace: None