Class: Sprockets::ImageCompressor::JpgCompressor

Inherits:
Base
  • Object
show all
Defined in:
lib/sprockets/image_compressor/jpg_compressor.rb

Instance Method Summary collapse

Methods inherited from Base

#binary_path

Constructor Details

#initializeJpgCompressor

Returns a new instance of JpgCompressor.



6
7
8
# File 'lib/sprockets/image_compressor/jpg_compressor.rb', line 6

def initialize
  @name = "jpegoptim"
end

Instance Method Details

#compress(content) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sprockets/image_compressor/jpg_compressor.rb', line 10

def compress(content)
  compressed_jpg_data = ""
  Tempfile.open ["file", ".jpg"] do |file|
    file.binmode
    file.write content
    file.close

    out = `#{binary_path} --strip-all #{file.path} 2>&1`
    compressed_jpg_data = IO.binread(file.path)
  end
  compressed_jpg_data
end