png_quantizator 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/png_quantizator.rb +3 -1
- data/lib/png_quantizator/version.rb +1 -1
- data/spec/png_quantizator/image_spec.rb +15 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 302f575beeda78b881993fda239f4d1fff9c114b
|
4
|
+
data.tar.gz: 633bb61eee57d2fba8a95774e867fe6a2582735f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 760f8e771bc53a8ffe14506e317c9bc6bc1cafb402b92ddbc528c93ee595962f65d132f6a6308f4156d89d1d84b764954b4190d4a174d21714d3d943c7abc403
|
7
|
+
data.tar.gz: 414a959102aba631a7176b4957a6cacb623e4c7ef6b3278d93a2520866ad190902d5b0e17166f4752f10f55057b9b52940ba221501df063fb2f956a2b0ef9ba8
|
data/lib/png_quantizator.rb
CHANGED
@@ -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
|
@@ -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("/
|
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("/
|
22
|
+
quantized.quantize_to("#{@tmpdir}/cucota.png").should be_true
|
16
23
|
|
17
|
-
File.file?("/
|
18
|
-
File.size("/
|
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("/
|
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) { "/
|
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
|
51
|
+
foo = `ls -1 #{@tmpdir}/*.png | wc -l`
|
45
52
|
PngQuantizator::Image.new(original_file_path).quantize!
|
46
|
-
foo.should == `ls -1
|
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.
|
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:
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|