Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you generate retina (iPad) friendly (progressive or interlaced) jpeg images with CarrierWave?

There are numerous reports that Mobile Safari downsamples very large JPEG images, making it difficult to put out retina-friendly resolutions for the new iPad.

The solution seems to be encoding JPEGs as progressive/interlaced files. Hence, I'm curious how I might use the CarrierWave plugin, and RMagick by extension, to generate this type of file.

Thanks!

like image 634
johnny Avatar asked Dec 09 '22 01:12

johnny


2 Answers

You can use MiniMagick:

manipulate! do |img|
  img.strip
  img.combine_options do |c|
    c.quality "90"
    c.depth "8"
    c.interlace "plane"
  end
  img
end
like image 81
Lucas Renan Avatar answered Dec 11 '22 15:12

Lucas Renan


As of today, you will need the repository version of carriewave as options[:write] support is not yet released.

So in your Gemfile, use the following:

gem 'carrierwave', :github => "jnicklas/carrierwave"

Then, in your uploader you can define something like follow:

version :big do
  process :resize_to_limit => [1024, 1024]
  process :optimize
end

def optimize
  manipulate! do |img, index, options|
    options[:write] = {
      :quality => 90, # Change the quality to 90%
      :depth => 8, # Set the depth to 8 bits
      :interlace => "Magick::PlaneInterlace" # Add progressive support for JPEG
    }
    img.strip! # Remove profile data
  end
end

Useful reference : http://www.imagemagick.org/RMagick/doc/constants.html#InterlaceType

Enjoy!

like image 21
Sébastien Grosjean - ZenCocoon Avatar answered Dec 11 '22 14:12

Sébastien Grosjean - ZenCocoon