image_squeeze 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,7 +23,7 @@ class ImageSqueeze
23
23
  attr_reader :processors
24
24
  attr_reader :tmpdir
25
25
 
26
- VERSION = '0.1.4'
26
+ VERSION = '0.1.5'
27
27
 
28
28
  # Image Types
29
29
  GIF = 'gif'
@@ -17,8 +17,13 @@ class ImageSqueeze
17
17
 
18
18
  end
19
19
 
20
+ def self.transparent?(filename)
21
+ `identify -format "%A %r" #{filename} 2> /dev/null`.split(' ').first == 'True'
22
+ end
23
+
20
24
  private
21
25
  def self.identified_format(filename)
22
26
  `identify -format %m #{filename} 2> /dev/null`
23
27
  end
28
+
24
29
  end
@@ -9,6 +9,11 @@ class ImageSqueeze
9
9
  end
10
10
 
11
11
  def self.squeeze(filename, output_filename)
12
+ if ImageSqueeze.transparent?(filename)
13
+ FileUtils.cp(filename, output_filename)
14
+ return
15
+ end
16
+
12
17
  intermediate_tmp_filename = "%s-%s" % [output_filename, '.tmp']
13
18
 
14
19
  system("convert #{filename} JPG:#{intermediate_tmp_filename} 2> /dev/null")
@@ -9,6 +9,11 @@ class ImageSqueeze
9
9
  end
10
10
 
11
11
  def self.squeeze(filename, output_filename)
12
+ if ImageSqueeze.transparent?(filename)
13
+ FileUtils.cp(filename, output_filename)
14
+ return
15
+ end
16
+
12
17
  intermediate_tmp_filename = "%s-%s" % [output_filename, '.tmp']
13
18
 
14
19
  system("convert #{filename} JPG:#{intermediate_tmp_filename} 2> /dev/null")
@@ -46,12 +46,21 @@ class DefaultProcessorsTest < Test::Unit::TestCase
46
46
  end
47
47
 
48
48
  def test_png_to_progressive_jpg
49
- assert_processor_optimizes_file(ImageSqueeze::PNGToProgressiveJPEGProcessor, 'better_as_jpg.png')
49
+ assert_processor_optimizes_file(ImageSqueeze::PNGToProgressiveJPEGProcessor, 'png_without_transparency.png')
50
+ end
51
+
52
+ def test_png_to_progressive_jpg_doesnt_convert_png_with_transparency
53
+ assert_processor_doesnt_optimize_file(ImageSqueeze::PNGToProgressiveJPEGProcessor, 'png_with_transparency.png')
50
54
  end
51
55
 
52
56
  def test_png_to_non_progressive_jpg
53
- assert_processor_optimizes_file(ImageSqueeze::PNGToProgressiveJPEGProcessor, 'better_as_jpg.png')
57
+ assert_processor_optimizes_file(ImageSqueeze::PNGToNonProgressiveJPEGProcessor, 'png_without_transparency.png')
54
58
  end
59
+
60
+ def test_png_to_non_progressive_jpg_doesnt_convert_png_with_transparency
61
+ assert_processor_doesnt_optimize_file(ImageSqueeze::PNGToNonProgressiveJPEGProcessor, 'png_with_transparency.png')
62
+ end
63
+
55
64
 
56
65
  private
57
66
  def assert_processor_optimizes_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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Grim
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-16 00:00:00 Z
18
+ date: 2012-07-17 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: a library for automated lossless image optimization
@@ -45,11 +45,12 @@ files:
45
45
  - test/fixtures/already_optimized_gif.gif
46
46
  - test/fixtures/already_optimized_jpg.jpg
47
47
  - test/fixtures/already_optimized_png.png
48
- - test/fixtures/better_as_jpg.png
49
48
  - test/fixtures/better_as_progressive.jpg
50
49
  - test/fixtures/better_without_progressive.jpg
51
50
  - test/fixtures/gif.gif.gif.gif
52
51
  - test/fixtures/mislabeled_gif.png
52
+ - test/fixtures/png_with_transparency.png
53
+ - test/fixtures/png_without_transparency.png
53
54
  - test/fixtures/textfile.txt
54
55
  - test/fixtures/unoptimized_animated_gif.gif
55
56
  - test/fixtures/unoptimized_gif.gif