Use ImageMagick to create optimised and progressive JPGs
Use the following command to optimise a JPG and make it progressive:
convert -strip -interlace Plane -quality 80 input-file.jpg output-file.jpg
Batch all the images in a folder like this:
for i in source/images/backgrounds/*.jpg; do convert -strip -interlace Plane -quality 80 $i $i; done
With Carrierwave and MiniMagick you can create an optimise function like this:
def optimize
manipulate! do |img|
return img unless img.mime_type.match /image\/jpeg/
img.strip
img.combine_options do |c|
c.quality "80"
c.depth "8"
c.interlace "plane"
end
img
end
end
And use it in your uploader like this:
version :large do
process :optimize
end
Written by Andrew Walker
Related protips
4 Responses

I didn't know about -interlace
, thanks for sharing :-)

Progressive JPEG doesn't work for me with MiniMagick 4.0.4.
Searching in the doc for an interlace
method found no result: http://www.rubydoc.info/search/github/minimagick/minimagick?q=interlace

@caedes MiniMagic uses ImageMagics command line program mogrify which has an interlace feature (https://github.com/minimagick/minimagick#solution)
Full list of supported mogrify commands can be found here: http://www.rubydoc.info/gems/mini_magick/3.3/MiniMagick

I wanna convert all images, including png, jpg, gif to progressive jpg and used this method, I got a new version of images, but the extension of file is not changed. For example, input.png only output progressive_input.png.