png_quantizator 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7dc995617bb0d74176532d50d16c6c1c1b94a8b
4
- data.tar.gz: d93546109649a9f7047e55fdc666c96d27d2048f
3
+ metadata.gz: 302f575beeda78b881993fda239f4d1fff9c114b
4
+ data.tar.gz: 633bb61eee57d2fba8a95774e867fe6a2582735f
5
5
  SHA512:
6
- metadata.gz: 5b075ad74169d8cd4ab45b5dd4f858275c036312512c037588c0f07684d14ec4620aed564e41e536be7549a40e4f582e8488a0465c5e5ec084143e260e6d6542
7
- data.tar.gz: 6a9aa1b6dfd5c25f9687c690b32e34093add1309981ec4311654929248f56a349b27009ec54a6477dce05b3c24100845b582a4fe575c9b3c9fad08537b347ca8
6
+ metadata.gz: 760f8e771bc53a8ffe14506e317c9bc6bc1cafb402b92ddbc528c93ee595962f65d132f6a6308f4156d89d1d84b764954b4190d4a174d21714d3d943c7abc403
7
+ data.tar.gz: 414a959102aba631a7176b4957a6cacb623e4c7ef6b3278d93a2520866ad190902d5b0e17166f4752f10f55057b9b52940ba221501df063fb2f956a2b0ef9ba8
@@ -3,6 +3,7 @@ require 'open3'
3
3
  require 'fileutils'
4
4
  require 'securerandom'
5
5
  require 'tempfile'
6
+ require 'shellwords'
6
7
 
7
8
  module PngQuantizator
8
9
  class PngQuantError < StandardError; end
@@ -30,8 +31,9 @@ module PngQuantizator
30
31
 
31
32
  exit_code, err_msg = Open3.popen3("pngquant #{colors}") do |stdin, stdout, stderr, wait_thr|
32
33
  stdin.write(File.read(@file_path))
34
+ stdin.close
33
35
 
34
- File.open(destination_path, "w") do |f|
36
+ File.open(Shellwords.escape(destination_path), "w") do |f|
35
37
  f.write stdout.gets(nil)
36
38
  f.flush
37
39
  end
@@ -1,3 +1,3 @@
1
1
  module PngQuantizator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -4,25 +4,32 @@ describe PngQuantizator::Image do
4
4
  let(:test_jpg) { File.join(File.dirname(__FILE__), "../data/sample.jpg") }
5
5
  let(:test_png) { File.join(File.dirname(__FILE__), "../data/sample.png") }
6
6
 
7
+ around do |block|
8
+ Dir.mktmpdir do |dir|
9
+ @tmpdir = dir
10
+ block.run
11
+ end
12
+ end
13
+
7
14
  describe "#quantize_to" do
8
15
  it "should not work with jpg files" do
9
16
  quantized = PngQuantizator::Image.new(test_jpg)
10
- expect { quantized.quantize_to("/tmp/cucota.png") }.to raise_error(PngQuantizator::PngQuantError)
17
+ expect { quantized.quantize_to("#{@tmpdir}/cucota.png") }.to raise_error(PngQuantizator::PngQuantError)
11
18
  end
12
19
 
13
20
  it "should work with png files" do
14
21
  quantized = PngQuantizator::Image.new(test_png)
15
- quantized.quantize_to("/tmp/cucota.png").should be_true
22
+ quantized.quantize_to("#{@tmpdir}/cucota.png").should be_true
16
23
 
17
- File.file?("/tmp/cucota.png").should be_true
18
- File.size("/tmp/cucota.png").should < File.size(test_png)
24
+ File.file?("#{@tmpdir}/cucota.png").should be_true
25
+ File.size("#{@tmpdir}/cucota.png").should < File.size(test_png)
19
26
 
20
- FileUtils.rm_rf("/tmp/cucota.png")
27
+ FileUtils.rm_rf("#{@tmpdir}/cucota.png")
21
28
  end
22
29
  end
23
30
 
24
31
  describe "#quantize!" do
25
- let(:original_file_path) { "/tmp/abracadabra.png" }
32
+ let(:original_file_path) { "#{@tmpdir}/abracadabra.png" }
26
33
 
27
34
  before do
28
35
  FileUtils.cp(test_png, original_file_path)
@@ -41,9 +48,9 @@ describe PngQuantizator::Image do
41
48
  end
42
49
 
43
50
  it "should not leave residual files in tmp" do
44
- foo = `ls -1 /tmp/*.png | wc -l`
51
+ foo = `ls -1 #{@tmpdir}/*.png | wc -l`
45
52
  PngQuantizator::Image.new(original_file_path).quantize!
46
- foo.should == `ls -1 /tmp/*.png | wc -l`
53
+ foo.should == `ls -1 #{@tmpdir}/*.png | wc -l`
47
54
  end
48
55
  end
49
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: png_quantizator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec