image_squeeze 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/image_squeeze.rb CHANGED
@@ -16,12 +16,14 @@ require 'image_squeeze/processors/jpeg_tran_non_progressive_processor'
16
16
  require 'image_squeeze/processors/gifsicle_processor'
17
17
  require 'image_squeeze/processors/gif_to_png_processor'
18
18
  require 'image_squeeze/processors/optipng_processor'
19
+ require 'image_squeeze/processors/png_to_progressive_jpeg_processor'
20
+ require 'image_squeeze/processors/png_to_non_progressive_jpeg_processor'
19
21
 
20
22
  class ImageSqueeze
21
23
  attr_reader :processors
22
24
  attr_reader :tmpdir
23
25
 
24
- VERSION = '0.1.3'
26
+ VERSION = '0.1.4'
25
27
 
26
28
  # Image Types
27
29
  GIF = 'gif'
@@ -114,6 +116,8 @@ class ImageSqueeze
114
116
  if ImageSqueeze::Utils.image_utility_available?('jpegtran', 'jpeg')
115
117
  processors << JPEGTranProgressiveProcessor
116
118
  processors << JPEGTranNonProgressiveProcessor
119
+ processors << PNGToProgressiveJPEGProcessor if ImageSqueeze::Utils.image_utility_available?('convert', 'png')
120
+ processors << PNGToNonProgressiveJPEGProcessor if ImageSqueeze::Utils.image_utility_available?('convert', 'png')
117
121
  end
118
122
  processors
119
123
  end
@@ -0,0 +1,22 @@
1
+ class ImageSqueeze
2
+ class PNGToNonProgressiveJPEGProcessor < Processor
3
+ def self.input_type
4
+ PNG
5
+ end
6
+
7
+ def self.output_extension
8
+ '.jpg'
9
+ end
10
+
11
+ def self.squeeze(filename, output_filename)
12
+ intermediate_tmp_filename = "%s-%s" % [output_filename, '.tmp']
13
+
14
+ system("convert #{filename} JPG:#{intermediate_tmp_filename} 2> /dev/null")
15
+ response = JPEGTranNonProgressiveProcessor.squeeze(intermediate_tmp_filename, output_filename) # run it through PNGCrush afterwards
16
+
17
+ FileUtils.rm(intermediate_tmp_filename) # clean up after ourselves
18
+
19
+ response
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class ImageSqueeze
2
+ class PNGToProgressiveJPEGProcessor < Processor
3
+ def self.input_type
4
+ PNG
5
+ end
6
+
7
+ def self.output_extension
8
+ '.jpg'
9
+ end
10
+
11
+ def self.squeeze(filename, output_filename)
12
+ intermediate_tmp_filename = "%s-%s" % [output_filename, '.tmp']
13
+
14
+ system("convert #{filename} JPG:#{intermediate_tmp_filename} 2> /dev/null")
15
+ response = JPEGTranProgressiveProcessor.squeeze(intermediate_tmp_filename, output_filename) # run it through PNGCrush afterwards
16
+
17
+ FileUtils.rm(intermediate_tmp_filename) # clean up after ourselves
18
+
19
+ response
20
+ end
21
+ end
22
+ end
Binary file
@@ -44,18 +44,22 @@ class DefaultProcessorsTest < Test::Unit::TestCase
44
44
  def test_gif_to_png_processor_with_unoptimized_gif
45
45
  assert_processor_optimizes_file(ImageSqueeze::GIFToPNGProcessor, 'unoptimized_gif.gif')
46
46
  end
47
+
48
+ def test_png_to_progressive_jpg
49
+ assert_processor_optimizes_file(ImageSqueeze::PNGToProgressiveJPEGProcessor, 'better_as_jpg.png')
50
+ end
47
51
 
48
- def test_gif_to_png_processor_with_already_optimized_animated_gif
49
- assert_processor_doesnt_optimize_file(ImageSqueeze::GIFToPNGProcessor, 'already_optimized_gif.gif')
52
+ def test_png_to_non_progressive_jpg
53
+ assert_processor_optimizes_file(ImageSqueeze::PNGToProgressiveJPEGProcessor, 'better_as_jpg.png')
50
54
  end
51
-
55
+
52
56
  private
53
57
  def assert_processor_optimizes_file(processor, file)
54
58
  squeezer = ImageSqueeze.new(:processors => [processor])
55
59
  filename = fixtures(file)
56
60
  old_size = File.size(filename)
57
61
  new_filename = squeezer.squeeze!(filename)
58
- assert File.size(new_filename) < old_size, "New file size of #{File.size(new_filename)} should be smaller than original of #{old_size}"
62
+ assert new_filename && File.size(new_filename) < old_size, "New file should be smaller than original of #{old_size}"
59
63
  end
60
64
 
61
65
  def assert_processor_doesnt_optimize_file(processor, file)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_squeeze
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Grim
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-21 00:00:00 -07:00
19
- default_executable:
18
+ date: 2012-07-16 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: a library for automated lossless image optimization
@@ -36,6 +35,8 @@ files:
36
35
  - lib/image_squeeze/processors/jpeg_tran_progressive_processor.rb
37
36
  - lib/image_squeeze/processors/optipng_processor.rb
38
37
  - lib/image_squeeze/processors/png_crush_processor.rb
38
+ - lib/image_squeeze/processors/png_to_non_progressive_jpeg_processor.rb
39
+ - lib/image_squeeze/processors/png_to_progressive_jpeg_processor.rb
39
40
  - lib/image_squeeze/processors/processor.rb
40
41
  - lib/image_squeeze/result.rb
41
42
  - lib/image_squeeze/utils.rb
@@ -44,6 +45,7 @@ files:
44
45
  - test/fixtures/already_optimized_gif.gif
45
46
  - test/fixtures/already_optimized_jpg.jpg
46
47
  - test/fixtures/already_optimized_png.png
48
+ - test/fixtures/better_as_jpg.png
47
49
  - test/fixtures/better_as_progressive.jpg
48
50
  - test/fixtures/better_without_progressive.jpg
49
51
  - test/fixtures/gif.gif.gif.gif
@@ -63,7 +65,6 @@ files:
63
65
  - LICENSE
64
66
  - Rakefile
65
67
  - README.md
66
- has_rdoc: true
67
68
  homepage: http://github.com/stopdropandrew/image_squeeze
68
69
  licenses: []
69
70
 
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - none
95
96
  rubyforge_project:
96
- rubygems_version: 1.6.2
97
+ rubygems_version: 1.8.8
97
98
  signing_key:
98
99
  specification_version: 3
99
100
  summary: a library for automated lossless image optimization