Sha256: 87bf69bf687026c2d11f6b8781649bdcb1e37b9cb2128245dc56c5bee96146b0

Contents?: true

Size: 756 Bytes

Versions: 1

Compression:

Stored size: 756 Bytes

Contents

require 'piet/carrierwave_extension'

module Piet
  class << self
    VALID_EXTS = %w{ png jpg jpeg }

    def optimize(path, opts={})
      output = optimize_for(path, opts)
      puts output if opts[:verbose]
      true
    end

    private

    def optimize_for(path, opts)
      case extension(path)
        when "png" then optimize_png(path, opts)
        when "jpg", "jpeg" then optimize_jpg(path, opts)
      end
    end

    def extension(path)
      path.split(".").last.downcase
    end

    def optimize_png(path, opts)
      vo = opts[:verbose] ? "-v" : "-quiet"
      `optipng -o7 #{vo} #{path}`
    end

    def optimize_jpg(path, opts)
      vo = opts[:verbose] ? "-v" : "-q"
      `jpegoptim -f --strip-all #{vo} #{path}`
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
piet-0.1.0 lib/piet.rb