Skip to content

Optimizing processed images

Patrick Crowley edited this page Apr 20, 2018 · 2 revisions

After images have been processed, you might want to additionally optimize them to reduce their filesize. The image_optim gem does this:

require "image_optim"

thumbnail = ImageProcessing::Vips
  .resize_to_limit(400, 400)
  .saver(quality: 85)
  .call(image)

image_optim = ImageOptim.new(...)
image_optim.optimize_image!(thumbnail.path)
thumbnail.open # refresh file descriptor

thumbnail # optimized thumbnail