lizard 1.0.0 → 1.0.1
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 +5 -5
- data/lib/lizard.rb +7 -3
- data/lib/lizard/error.rb +9 -0
- data/lib/lizard/image.rb +55 -13
- data/lib/lizard/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 63f00a1bac30a62ffd03c7cc7a0660150769272cc316a12685ef59ccd3c3c0be
|
4
|
+
data.tar.gz: 8ad60b2e0f4c93fb5c102cffabeec6b3ea3b76b1d3fcb0f8fd628ec6d19be590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a8e9d888e276ba5a5f4dda4c0f3da9f645cb412058a02b8d0036ffd00ff64d602a2e99cce0b72eff6d93054b18a749a88cf11233634e214445037a3af01c08d
|
7
|
+
data.tar.gz: 49fd5024b86b62fc7e145b750b81246cc19eedee09e49fd6f3c4c25024923050ebc4be81b1bbeacb3a2f5462af21062097063212440121496728b351c253e297
|
data/lib/lizard.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
require 'open3'
|
2
2
|
|
3
3
|
module Lizard
|
4
|
-
|
5
4
|
def self.root
|
6
5
|
File.expand_path('../../', __FILE__)
|
7
6
|
end
|
8
7
|
|
9
8
|
def self.run_command(command, input = nil)
|
10
|
-
|
9
|
+
command = [command] unless command.is_a?(Array)
|
10
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3(*command)
|
11
|
+
stdin.binmode
|
12
|
+
stdout.binmode
|
13
|
+
stderr.binmode
|
11
14
|
stdin.write(input) if input
|
12
15
|
stdin.close
|
13
16
|
[stdout.read, stderr.read, wait_thr.value.to_i]
|
14
17
|
end
|
15
|
-
|
16
18
|
end
|
19
|
+
|
20
|
+
require 'lizard/image'
|
data/lib/lizard/error.rb
CHANGED
data/lib/lizard/image.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "tempfile"
|
2
|
+
require "lizard/color_profiles"
|
3
|
+
require "lizard/error"
|
4
|
+
require "lizard/histogram"
|
5
5
|
|
6
6
|
module Lizard
|
7
7
|
class Image
|
8
8
|
|
9
|
+
TYPES = ['jpeg', 'png', 'gif']
|
10
|
+
|
9
11
|
def self.is_image?(data)
|
10
12
|
image = Image.new(data)
|
11
13
|
true
|
@@ -18,6 +20,10 @@ module Lizard
|
|
18
20
|
@properties = identify
|
19
21
|
end
|
20
22
|
|
23
|
+
def inspect
|
24
|
+
"#<Lizard::Image type=#{type}, size=#{width}x#{height}, bytes=#{@data.bytesize}>"
|
25
|
+
end
|
26
|
+
|
21
27
|
def data
|
22
28
|
@data
|
23
29
|
end
|
@@ -44,19 +50,41 @@ module Lizard
|
|
44
50
|
|
45
51
|
def color_model
|
46
52
|
case color_space
|
47
|
-
when/CMYK/i then
|
48
|
-
when /RGB/i then
|
53
|
+
when/CMYK/i then "CMYK"
|
54
|
+
when /RGB/i then "RBG"
|
49
55
|
else nil
|
50
56
|
end
|
51
57
|
end
|
52
58
|
|
53
|
-
def resize(width, height)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
59
|
+
def resize(width, height, mode = :resize_down_only, type = "jpeg")
|
60
|
+
case mode
|
61
|
+
when :default
|
62
|
+
operator = ""
|
63
|
+
when :resize_down_only
|
64
|
+
operator = ">"
|
65
|
+
when :fill
|
66
|
+
operator = "^"
|
67
|
+
when :ignore_aspect
|
68
|
+
operator = "!"
|
69
|
+
else
|
70
|
+
raise InvalidResizeMode, "#{mode} is not a valid"
|
58
71
|
end
|
59
|
-
|
72
|
+
|
73
|
+
unless TYPES.include?(type)
|
74
|
+
raise InvalidFileType, "#{type} is not valid. Choose from #{TYPES.join(', ')}"
|
75
|
+
end
|
76
|
+
|
77
|
+
command = [
|
78
|
+
'convert', '-', '-profile', Lizard::COLOR_PROFILES["RGB"], '-flatten',
|
79
|
+
'-resize', "#{width.to_i}x#{height.to_i}#{operator}",
|
80
|
+
"#{type}:-"
|
81
|
+
]
|
82
|
+
if self.color_model == "CMYK"
|
83
|
+
command.insert(4, '-profile')
|
84
|
+
command.insert(5, COLOR_PROFILES[self.color_model].to_s)
|
85
|
+
end
|
86
|
+
|
87
|
+
stdout, stderr, exit_code = Lizard.run_command(command, @data)
|
60
88
|
if exit_code == 0
|
61
89
|
Image.new(stdout)
|
62
90
|
else
|
@@ -64,6 +92,20 @@ module Lizard
|
|
64
92
|
end
|
65
93
|
end
|
66
94
|
|
95
|
+
def crop(width, height, type = "jpeg")
|
96
|
+
unless TYPES.include?(type)
|
97
|
+
raise InvalidFileType, "#{type} is not valid. Choose from #{TYPES.join(', ')}"
|
98
|
+
end
|
99
|
+
|
100
|
+
command = ['convert', '-', '-gravity', 'center', '-extent', "#{width.to_i}x#{height.to_i}", "#{type}:-"]
|
101
|
+
stdout, stderr, exit_code = Lizard.run_command(command, @data)
|
102
|
+
if exit_code == 0
|
103
|
+
Image.new(stdout)
|
104
|
+
else
|
105
|
+
raise CropFailed, "Image could not be cropped (#{stderr})"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
67
109
|
def histogram
|
68
110
|
@histogram ||= Histogram.new(@data)
|
69
111
|
end
|
@@ -74,7 +116,7 @@ module Lizard
|
|
74
116
|
stdout, stderr, exit_code = Lizard.run_command(%Q{identify -format "Lizard||%m||%[resolution.x]x%[resolution.y]||%wx%h||%r" -}, @data)
|
75
117
|
if exit_code == 0 && stdout =~ /\ALizard\|\|/
|
76
118
|
_, type, resolution, size, color_space = stdout.split("||")
|
77
|
-
width, height = size.split(
|
119
|
+
width, height = size.split("x")
|
78
120
|
{:type => type, :resolution => resolution, :width => width, :height => height, :size => size, :color_space => color_space}
|
79
121
|
else
|
80
122
|
raise NotAnImage, stderr
|
data/lib/lizard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lizard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Very simple ImageMagick interface for Ruby
|
14
14
|
email:
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
74
|
rubyforge_project:
|
75
|
-
rubygems_version: 2.
|
75
|
+
rubygems_version: 2.7.4
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: Very simple ImageMagick interface for Ruby
|