Skip to content

Doing conditional processing

Janko Marohnić edited this page Nov 16, 2019 · 2 revisions

With the dynamic chainable API it's very easy to do conditional processing:

pipeline = ImageProcessing::Vips
  .source(image)
  .resize_to_limit(400, 400)

if image.path.match?(/\.jpe?g$/i)
  pipeline = pipeline
    .saver(interlace: true) # create only interlaced JPEGs, excluding PNGs
    .sharpen(sigma: 0.5, x1: 2, y2: 10, y3: 20, m1: 0, m2: 3) # sharpen only JPEGs
end

pipeline.call #=> #<File:/tmp/...>