Sha256: e6006ece3c6f0f4458f710c68da360efd4a3cad1ad202e884257142cfdbae89f

Contents?: true

Size: 1.22 KB

Versions: 16

Compression:

Stored size: 1.22 KB

Contents

require 'image_optim/worker'

class ImageOptim
  class Worker
    # http://www.ijg.org/
    #
    # Uses jpegtran through jpegrescan if enabled, jpegrescan is vendored with
    # this gem
    class Jpegtran < Worker
      COPY_CHUNKS_OPTION =
      option(:copy_chunks, false, 'Copy all chunks'){ |v| !!v }

      PROGRESSIVE_OPTION =
      option(:progressive, true, 'Create progressive JPEG file'){ |v| !!v }

      JPEGRESCAN_OPTION =
      option(:jpegrescan, false, 'Use jpegtran through jpegrescan, '\
          'ignore progressive option'){ |v| !!v }

      def used_bins
        jpegrescan ? [:jpegtran, :jpegrescan] : [:jpegtran]
      end

      def optimize(src, dst)
        if jpegrescan
          args = %W[
            #{src}
            #{dst}
          ]
          args.unshift '-s' unless copy_chunks
          resolve_bin!(:jpegtran)
          execute(:jpegrescan, *args) && optimized?(src, dst)
        else
          args = %W[
            -optimize
            -outfile #{dst}
            #{src}
          ]
          args.unshift '-copy', (copy_chunks ? 'all' : 'none')
          args.unshift '-progressive' if progressive
          execute(:jpegtran, *args) && optimized?(src, dst)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
image_optim-0.25.0 lib/image_optim/worker/jpegtran.rb
image_optim-0.24.3 lib/image_optim/worker/jpegtran.rb
image_optim-0.24.2 lib/image_optim/worker/jpegtran.rb
image_optim-0.24.1 lib/image_optim/worker/jpegtran.rb
image_optim-0.24.0 lib/image_optim/worker/jpegtran.rb
image_optim-0.23.0 lib/image_optim/worker/jpegtran.rb
image_optim-0.22.1 lib/image_optim/worker/jpegtran.rb
image_optim-0.22.0 lib/image_optim/worker/jpegtran.rb
openstreetmap-image_optim-0.21.0.1 lib/image_optim/worker/jpegtran.rb
image_optim-0.21.0 lib/image_optim/worker/jpegtran.rb
image_optim-0.20.2 lib/image_optim/worker/jpegtran.rb
image_optim-0.20.1 lib/image_optim/worker/jpegtran.rb
image_optim-0.20.0 lib/image_optim/worker/jpegtran.rb
image_optim-0.19.1 lib/image_optim/worker/jpegtran.rb
image_optim-0.19.0 lib/image_optim/worker/jpegtran.rb
image_optim-0.18.0 lib/image_optim/worker/jpegtran.rb