chunky_png 1.2.9 → 1.3.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.
- data/.travis.yml +3 -4
- data/Gemfile +4 -0
- data/README.rdoc +1 -1
- data/lib/chunky_png/canvas/operations.rb +47 -0
- data/lib/chunky_png/color.rb +20 -12
- data/lib/chunky_png/version.rb +1 -1
- data/spec/chunky_png/canvas/operations_spec.rb +134 -57
- data/spec/chunky_png/color_spec.rb +8 -3
- data/spec/resources/operations_border.png +0 -0
- metadata +13 -6
- checksums.yaml +0 -15
data/.travis.yml
CHANGED
@@ -2,16 +2,15 @@ language: ruby
|
|
2
2
|
script: bundle exec rake
|
3
3
|
rvm:
|
4
4
|
- 1.8.7
|
5
|
-
- 1.9.2
|
6
5
|
- 1.9.3
|
7
6
|
- 2.0.0
|
7
|
+
- 2.1.0
|
8
8
|
- ruby-head
|
9
9
|
- ree
|
10
|
-
- rbx
|
11
|
-
- rbx-19mode
|
10
|
+
- rbx
|
12
11
|
- jruby-18mode
|
13
12
|
- jruby-19mode
|
14
13
|
matrix:
|
15
14
|
allow_failures:
|
16
|
-
- rvm: rbx
|
15
|
+
- rvm: rbx
|
17
16
|
- rvm: ruby-head
|
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Chunky PNG
|
1
|
+
= Chunky PNG {<img src="https://travis-ci.org/wvanbergen/chunky_png.png?branch=master" alt="Build Status" />}[https://travis-ci.org/wvanbergen/chunky_png]
|
2
2
|
|
3
3
|
This library can read and write PNG files. It is written in pure Ruby for
|
4
4
|
maximum portability. Let me rephrase: it does NOT require RMagick or any other
|
@@ -296,6 +296,53 @@ module ChunkyPNG
|
|
296
296
|
return self
|
297
297
|
end
|
298
298
|
|
299
|
+
# Trims the border around the image, presumed to be the color of the first pixel.
|
300
|
+
#
|
301
|
+
# @param [Integer] border The color to attempt to trim.
|
302
|
+
# @return [ChunkyPNG::Canvas] The trimmed image.
|
303
|
+
# @see #trim!
|
304
|
+
def trim(border = pixels.first)
|
305
|
+
dup.trim!
|
306
|
+
end
|
307
|
+
|
308
|
+
# Trims the border around the image in place.
|
309
|
+
#
|
310
|
+
# @param [Integer] border The color to attempt to trim.
|
311
|
+
# @return [ChunkyPNG::Canvas] Returns itself, but with the border trimmed.
|
312
|
+
# @see #trim
|
313
|
+
def trim!(border = pixels.first)
|
314
|
+
x1 = [*0...width].index { |c| column(c).uniq != [border] }
|
315
|
+
x2 = [*0...width].rindex { |c| column(c).uniq != [border] }
|
316
|
+
y1 = [*0...height].index { |r| row(r).uniq != [border] }
|
317
|
+
y2 = [*0...height].rindex { |r| row(r).uniq != [border] }
|
318
|
+
|
319
|
+
crop! x1, y1, x2 - x1 + 1, y2 - y1 + 1
|
320
|
+
end
|
321
|
+
|
322
|
+
# Draws a border around the image.
|
323
|
+
#
|
324
|
+
# @param [Integer] size The size of the border.
|
325
|
+
# @param [Integer] color The color of the border.
|
326
|
+
# @return [ChunkyPNG::Canvas] Returns a bordered version of the image.
|
327
|
+
# @see #border!
|
328
|
+
def border(size, color = ChunkyPNG::Color::BLACK)
|
329
|
+
dup.border!(size, color)
|
330
|
+
end
|
331
|
+
|
332
|
+
# Draws a border around the image in place.
|
333
|
+
#
|
334
|
+
# @param [Integer] size The size of the border.
|
335
|
+
# @param [Integer] color The color of the border.
|
336
|
+
# @return [ChunkyPNG::Canvas] Returns itself with the border added.
|
337
|
+
# @see #border
|
338
|
+
def border!(size, color = ChunkyPNG::Color::BLACK)
|
339
|
+
new_width = width + size * 2
|
340
|
+
new_height = height + size * 2
|
341
|
+
|
342
|
+
bg = Canvas.new(new_width, new_height, color).replace(self, size, size)
|
343
|
+
replace_canvas!(new_width, new_height, bg.pixels)
|
344
|
+
end
|
345
|
+
|
299
346
|
protected
|
300
347
|
|
301
348
|
# Checks whether another image has the correct dimension to be used for an operation
|
data/lib/chunky_png/color.rb
CHANGED
@@ -56,8 +56,12 @@ module ChunkyPNG
|
|
56
56
|
MAX = 0xff
|
57
57
|
|
58
58
|
# @private
|
59
|
-
# @return [Regexp] The regexp to parse hex color values.
|
60
|
-
|
59
|
+
# @return [Regexp] The regexp to parse 3-digit hex color values.
|
60
|
+
HEX3_COLOR_REGEXP = /\A(?:#|0x)?([0-9a-f]{3})\z/i
|
61
|
+
|
62
|
+
# @private
|
63
|
+
# @return [Regexp] The regexp to parse 6- and 8-digit hex color values.
|
64
|
+
HEX6_COLOR_REGEXP = /\A(?:#|0x)?([0-9a-f]{6})([0-9a-f]{2})?\z/i
|
61
65
|
|
62
66
|
# @private
|
63
67
|
# @return [Regexp] The regexp to parse named color values.
|
@@ -77,8 +81,8 @@ module ChunkyPNG
|
|
77
81
|
return source if source.kind_of?(Integer)
|
78
82
|
case source.to_s
|
79
83
|
when /^\d+$/; source.to_s.to_i
|
80
|
-
when
|
81
|
-
when
|
84
|
+
when HEX3_COLOR_REGEXP, HEX6_COLOR_REGEXP; from_hex(source.to_s)
|
85
|
+
when HTML_COLOR_REGEXP; html_color(source.to_s)
|
82
86
|
else raise ArgumentError, "Don't know how to create a color from #{source.inspect}!"
|
83
87
|
end
|
84
88
|
end
|
@@ -143,7 +147,8 @@ module ChunkyPNG
|
|
143
147
|
|
144
148
|
# Creates a color by converting it from a string in hex notation.
|
145
149
|
#
|
146
|
-
# It supports colors with (#rrggbbaa) or without (#rrggbb) alpha channel
|
150
|
+
# It supports colors with (#rrggbbaa) or without (#rrggbb) alpha channel
|
151
|
+
# as well as the 3-digit short format (#rgb) for those without.
|
147
152
|
# Color strings may include the prefix "0x" or "#".
|
148
153
|
#
|
149
154
|
# @param [String] str The color in hex notation. @return [Integer] The
|
@@ -153,13 +158,16 @@ module ChunkyPNG
|
|
153
158
|
# @return [Integer] The color value.
|
154
159
|
# @raise [ArgumentError] if the value given is not a hex color notation.
|
155
160
|
def from_hex(hex_value, opacity = nil)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
161
|
+
base_color = case hex_value
|
162
|
+
when HEX3_COLOR_REGEXP
|
163
|
+
$1.gsub(/([0-9a-f])/i, '\1\1').hex << 8
|
164
|
+
when HEX6_COLOR_REGEXP
|
165
|
+
$1.hex << 8
|
166
|
+
else
|
167
|
+
raise ArgumentError, "Not a valid hex color notation: #{hex_value.inspect}!"
|
168
|
+
end
|
169
|
+
opacity ||= $2 ? $2.hex : 0xff
|
170
|
+
base_color | opacity
|
163
171
|
end
|
164
172
|
|
165
173
|
####################################################################
|
data/lib/chunky_png/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ChunkyPNG::Canvas::Operations do
|
4
|
-
|
5
|
-
subject { reference_canvas('operations') }
|
6
|
-
|
4
|
+
|
5
|
+
subject { reference_canvas('operations') }
|
6
|
+
|
7
7
|
describe '#grayscale' do
|
8
8
|
it "should not return itself" do
|
9
9
|
subject.grayscale.should_not equal(subject)
|
@@ -12,12 +12,12 @@ describe ChunkyPNG::Canvas::Operations do
|
|
12
12
|
it "should convert the image correctly" do
|
13
13
|
subject.grayscale.should == reference_canvas('operations_grayscale')
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "should not adjust the current image" do
|
17
|
-
lambda { subject.
|
17
|
+
lambda { subject.grayscale }.should_not change(subject, :pixels)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
describe '#grayscale!' do
|
22
22
|
it "should return itself" do
|
23
23
|
subject.grayscale!.should equal(subject)
|
@@ -27,32 +27,32 @@ describe ChunkyPNG::Canvas::Operations do
|
|
27
27
|
subject.grayscale!
|
28
28
|
subject.should == reference_canvas('operations_grayscale')
|
29
29
|
end
|
30
|
-
end
|
31
|
-
|
30
|
+
end
|
31
|
+
|
32
32
|
describe '#crop' do
|
33
33
|
it "should crop the right pixels from the original canvas" do
|
34
34
|
subject.crop(10, 5, 4, 8).should == reference_canvas('cropped')
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should not return itself" do
|
38
38
|
subject.crop(10, 5, 4, 8).should_not equal(subject)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "should not adjust the current image" do
|
42
42
|
lambda { subject.crop(10, 5, 4, 8) }.should_not change(subject, :pixels)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should raise an exception when the cropped image falls outside the oiginal image" do
|
46
46
|
lambda { subject.crop(16, 16, 2, 2) }.should raise_error(ChunkyPNG::OutOfBounds)
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
describe '#crop!' do
|
51
51
|
it "should crop the right pixels from the original canvas" do
|
52
52
|
subject.crop!(10, 5, 4, 8)
|
53
53
|
subject.should == reference_canvas('cropped')
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should have a new width and height" do
|
57
57
|
lambda { subject.crop!(10, 5, 4, 8) }.should change(subject, :dimension).
|
58
58
|
from(ChunkyPNG::Dimension('16x16')).
|
@@ -62,7 +62,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
62
62
|
it "should raise an exception when the cropped image falls outside the oiginal image" do
|
63
63
|
lambda { subject.crop!(16, 16, 2, 2) }.should raise_error(ChunkyPNG::OutOfBounds)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
it "should return itself" do
|
67
67
|
subject.crop!(10, 5, 4, 8).should equal(subject)
|
68
68
|
end
|
@@ -73,42 +73,42 @@ describe ChunkyPNG::Canvas::Operations do
|
|
73
73
|
subcanvas = ChunkyPNG::Canvas.new(4, 8, ChunkyPNG::Color.rgba(0, 0, 0, 75))
|
74
74
|
subject.compose(subcanvas, 8, 4).should == reference_canvas('composited')
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it "should leave the original intact" do
|
78
78
|
subject.compose(ChunkyPNG::Canvas.new(1,1))
|
79
79
|
subject.should == reference_canvas('operations')
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should not return itself" do
|
83
83
|
subject.compose(ChunkyPNG::Canvas.new(1,1)).should_not equal(subject)
|
84
|
-
end
|
85
|
-
|
84
|
+
end
|
85
|
+
|
86
86
|
it "should raise an exception when the pixels to compose fall outside the image" do
|
87
87
|
lambda { subject.compose(ChunkyPNG::Canvas.new(1,1), 16, 16) }.should raise_error(ChunkyPNG::OutOfBounds)
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
describe '#compose!' do
|
92
92
|
it "should compose pixels correctly" do
|
93
93
|
subcanvas = ChunkyPNG::Canvas.new(4, 8, ChunkyPNG::Color.rgba(0, 0, 0, 75))
|
94
94
|
subject.compose!(subcanvas, 8, 4)
|
95
95
|
subject.should == reference_canvas('composited')
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it "should return itself" do
|
99
99
|
subject.compose!(ChunkyPNG::Canvas.new(1,1)).should equal(subject)
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
it "should compose a base image and mask correctly" do
|
103
103
|
base = reference_canvas('clock_base')
|
104
104
|
mask = reference_canvas('clock_mask_updated')
|
105
105
|
base.compose!(mask)
|
106
106
|
base.should == reference_canvas('clock_updated')
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
it "should raise an exception when the pixels to compose fall outside the image" do
|
110
110
|
lambda { subject.compose!(ChunkyPNG::Canvas.new(1,1), 16, 16) }.should raise_error(ChunkyPNG::OutOfBounds)
|
111
|
-
end
|
111
|
+
end
|
112
112
|
end
|
113
113
|
|
114
114
|
describe '#replace' do
|
@@ -116,32 +116,32 @@ describe ChunkyPNG::Canvas::Operations do
|
|
116
116
|
subcanvas = ChunkyPNG::Canvas.new(3, 2, ChunkyPNG::Color.rgb(200, 255, 0))
|
117
117
|
subject.replace(subcanvas, 5, 4).should == reference_canvas('replaced')
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
it "should not return itself" do
|
121
121
|
subject.replace(ChunkyPNG::Canvas.new(1,1)).should_not equal(subject)
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
it "should leave the original intact" do
|
125
125
|
subject.replace(ChunkyPNG::Canvas.new(1,1))
|
126
126
|
subject.should == reference_canvas('operations')
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
it "should raise an exception when the pixels to replace fall outside the image" do
|
130
130
|
lambda { subject.replace(ChunkyPNG::Canvas.new(1,1), 16, 16) }.should raise_error(ChunkyPNG::OutOfBounds)
|
131
131
|
end
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
describe '#replace!' do
|
135
135
|
it "should replace the correct pixels" do
|
136
136
|
subcanvas = ChunkyPNG::Canvas.new(3, 2, ChunkyPNG::Color.rgb(200, 255, 0))
|
137
137
|
subject.replace!(subcanvas, 5, 4)
|
138
138
|
subject.should == reference_canvas('replaced')
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
it "should return itself" do
|
142
142
|
subject.replace!(ChunkyPNG::Canvas.new(1,1)).should equal(subject)
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it "should raise an exception when the pixels to replace fall outside the image" do
|
146
146
|
lambda { subject.replace!(ChunkyPNG::Canvas.new(1,1), 16, 16) }.should raise_error(ChunkyPNG::OutOfBounds)
|
147
147
|
end
|
@@ -149,7 +149,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
describe ChunkyPNG::Canvas::Operations do
|
152
|
-
|
152
|
+
|
153
153
|
subject { ChunkyPNG::Canvas.new(2, 3, [1, 2, 3, 4, 5, 6]) }
|
154
154
|
|
155
155
|
describe '#flip_horizontally!' do
|
@@ -157,7 +157,7 @@ describe ChunkyPNG::Canvas::Operations do
|
|
157
157
|
subject.flip_horizontally!
|
158
158
|
subject.should == ChunkyPNG::Canvas.new(2, 3, [5, 6, 3, 4, 1, 2])
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
it "should return itself" do
|
162
162
|
subject.flip_horizontally!.should equal(subject)
|
163
163
|
end
|
@@ -167,22 +167,22 @@ describe ChunkyPNG::Canvas::Operations do
|
|
167
167
|
it "should flip the pixels horizontally" do
|
168
168
|
subject.flip_horizontally.should == ChunkyPNG::Canvas.new(2, 3, [5, 6, 3, 4, 1, 2])
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
it "should not return itself" do
|
172
172
|
subject.flip_horizontally.should_not equal(subject)
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
it "should return a copy of itself when applied twice" do
|
176
176
|
subject.flip_horizontally.flip_horizontally.should == subject
|
177
177
|
end
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
describe '#flip_vertically!' do
|
181
181
|
it "should flip the pixels vertically" do
|
182
182
|
subject.flip_vertically!
|
183
183
|
subject.should == ChunkyPNG::Canvas.new(2, 3, [2, 1, 4, 3, 6, 5])
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
it "should return itself" do
|
187
187
|
subject.flip_horizontally!.should equal(subject)
|
188
188
|
end
|
@@ -192,11 +192,11 @@ describe ChunkyPNG::Canvas::Operations do
|
|
192
192
|
it "should flip the pixels vertically" do
|
193
193
|
subject.flip_vertically.should == ChunkyPNG::Canvas.new(2, 3, [2, 1, 4, 3, 6, 5])
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
it "should not return itself" do
|
197
197
|
subject.flip_horizontally.should_not equal(subject)
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
it "should return a copy of itself when applied twice" do
|
201
201
|
subject.flip_vertically.flip_vertically.should == subject
|
202
202
|
end
|
@@ -206,38 +206,38 @@ describe ChunkyPNG::Canvas::Operations do
|
|
206
206
|
it "should rotate the pixels 90 degrees counter-clockwise" do
|
207
207
|
subject.rotate_left.should == ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5] )
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
it "should not return itself" do
|
211
211
|
subject.rotate_left.should_not equal(subject)
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
it "should not change the image dimensions" do
|
215
215
|
lambda { subject.rotate_left }.should_not change(subject, :dimension)
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
it "it should rotate 180 degrees when applied twice" do
|
219
219
|
subject.rotate_left.rotate_left.should == subject.rotate_180
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
it "it should rotate right when applied three times" do
|
223
223
|
subject.rotate_left.rotate_left.rotate_left.should == subject.rotate_right
|
224
224
|
end
|
225
|
-
|
225
|
+
|
226
226
|
it "should return itself when applied four times" do
|
227
227
|
subject.rotate_left.rotate_left.rotate_left.rotate_left.should == subject
|
228
228
|
end
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
describe '#rotate_left!' do
|
232
232
|
it "should rotate the pixels 90 degrees clockwise" do
|
233
233
|
subject.rotate_left!
|
234
234
|
subject.should == ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5] )
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
it "should return itself" do
|
238
238
|
subject.rotate_left!.should equal(subject)
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
it "should change the image dimensions" do
|
242
242
|
lambda { subject.rotate_left! }.should change(subject, :dimension).from(ChunkyPNG::Dimension('2x3')).to(ChunkyPNG::Dimension('3x2'))
|
243
243
|
end
|
@@ -247,38 +247,38 @@ describe ChunkyPNG::Canvas::Operations do
|
|
247
247
|
it "should rotate the pixels 90 degrees clockwise" do
|
248
248
|
subject.rotate_right.should == ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2] )
|
249
249
|
end
|
250
|
-
|
250
|
+
|
251
251
|
it "should not return itself" do
|
252
252
|
subject.rotate_right.should_not equal(subject)
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
it "should not change the image dimensions" do
|
256
256
|
lambda { subject.rotate_right }.should_not change(subject, :dimension)
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
it "it should rotate 180 degrees when applied twice" do
|
260
260
|
subject.rotate_right.rotate_right.should == subject.rotate_180
|
261
261
|
end
|
262
|
-
|
262
|
+
|
263
263
|
it "it should rotate left when applied three times" do
|
264
264
|
subject.rotate_right.rotate_right.rotate_right.should == subject.rotate_left
|
265
265
|
end
|
266
|
-
|
266
|
+
|
267
267
|
it "should return itself when applied four times" do
|
268
268
|
subject.rotate_right.rotate_right.rotate_right.rotate_right.should == subject
|
269
269
|
end
|
270
270
|
end
|
271
|
-
|
271
|
+
|
272
272
|
describe '#rotate_right!' do
|
273
273
|
it "should rotate the pixels 90 degrees clockwise" do
|
274
274
|
subject.rotate_right!
|
275
275
|
subject.should == ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2] )
|
276
276
|
end
|
277
|
-
|
277
|
+
|
278
278
|
it "should return itself" do
|
279
279
|
subject.rotate_right!.should equal(subject)
|
280
280
|
end
|
281
|
-
|
281
|
+
|
282
282
|
it "should change the image dimensions" do
|
283
283
|
lambda { subject.rotate_right! }.should change(subject, :dimension).from(ChunkyPNG::Dimension('2x3')).to(ChunkyPNG::Dimension('3x2'))
|
284
284
|
end
|
@@ -288,24 +288,101 @@ describe ChunkyPNG::Canvas::Operations do
|
|
288
288
|
it "should rotate the pixels 180 degrees" do
|
289
289
|
subject.rotate_180.should == ChunkyPNG::Canvas.new(2, 3, [6, 5, 4, 3, 2, 1])
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
it "should return not itself" do
|
293
293
|
subject.rotate_180.should_not equal(subject)
|
294
294
|
end
|
295
|
-
|
295
|
+
|
296
296
|
it "should return a copy of itself when applied twice" do
|
297
297
|
subject.rotate_180.rotate_180.should == subject
|
298
298
|
end
|
299
299
|
end
|
300
|
-
|
300
|
+
|
301
301
|
describe '#rotate_180!' do
|
302
302
|
it "should rotate the pixels 180 degrees" do
|
303
303
|
subject.rotate_180!
|
304
304
|
subject.should == ChunkyPNG::Canvas.new(2, 3, [6, 5, 4, 3, 2, 1])
|
305
305
|
end
|
306
|
-
|
306
|
+
|
307
307
|
it "should return itself" do
|
308
308
|
subject.rotate_180!.should equal(subject)
|
309
309
|
end
|
310
310
|
end
|
311
311
|
end
|
312
|
+
|
313
|
+
describe ChunkyPNG::Canvas::Operations do
|
314
|
+
|
315
|
+
subject { ChunkyPNG::Canvas.new(4, 4).rect(1, 1, 2, 2, 255, 255) }
|
316
|
+
|
317
|
+
describe "#trim" do
|
318
|
+
it "should trim the border" do
|
319
|
+
subject.trim.should == ChunkyPNG::Canvas.new(2, 2, 255)
|
320
|
+
end
|
321
|
+
|
322
|
+
it "should not return itself" do
|
323
|
+
subject.trim.should_not equal(subject)
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should be able to fail to trim a specified color" do
|
327
|
+
lambda { subject.trim(ChunkyPNG::Color::BLACK) }.should_not change(subject, :pixels)
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should be the same after trimming an added border" do
|
331
|
+
subject.border(2).trim.should == subject
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
describe "#trim!" do
|
336
|
+
it "should trim the border" do
|
337
|
+
subject.trim!
|
338
|
+
subject.should == ChunkyPNG::Canvas.new(2, 2, 255)
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should return itself" do
|
342
|
+
subject.trim!.should equal(subject)
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should change the image dimensions" do
|
346
|
+
lambda { subject.trim! }.should change(subject, :dimension).from(ChunkyPNG::Dimension('4x4')).to(ChunkyPNG::Dimension('2x2'))
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
describe ChunkyPNG::Canvas::Operations do
|
352
|
+
|
353
|
+
subject { ChunkyPNG::Canvas.new(4, 4) }
|
354
|
+
|
355
|
+
describe "#border" do
|
356
|
+
it "should add the border" do
|
357
|
+
subject.border(2).should == reference_canvas('operations_border')
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should not return itself" do
|
361
|
+
subject.border(1).should_not equal(subject)
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should retain transparency" do
|
365
|
+
ChunkyPNG::Canvas.new(1, 1).border(1).pixels.should include(0)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
describe "#border!" do
|
370
|
+
it "should add the border" do
|
371
|
+
subject.border!(2)
|
372
|
+
subject.should == reference_canvas('operations_border')
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should return itself" do
|
376
|
+
subject.border!(1).should equal(subject)
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should retain transparency" do
|
380
|
+
subject.border!(1)
|
381
|
+
subject.pixels.should include(0)
|
382
|
+
end
|
383
|
+
|
384
|
+
it "should change the image dimensions" do
|
385
|
+
lambda { subject.border!(1) }.should change(subject, :dimension).from(ChunkyPNG::Dimension('4x4')).to(ChunkyPNG::Dimension('6x6'))
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
@@ -88,18 +88,23 @@ describe ChunkyPNG::Color do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
describe '#from_hex' do
|
91
|
-
it "should load colors
|
91
|
+
it "should load colors correctly from hex notation" do
|
92
92
|
from_hex('0a649664').should == @non_opaque
|
93
93
|
from_hex('#0a649664').should == @non_opaque
|
94
94
|
from_hex('0x0a649664').should == @non_opaque
|
95
95
|
from_hex('0a6496').should == @opaque
|
96
96
|
from_hex('#0a6496').should == @opaque
|
97
97
|
from_hex('0x0a6496').should == @opaque
|
98
|
+
from_hex('abc').should == 0xaabbccff
|
99
|
+
from_hex('#abc').should == 0xaabbccff
|
100
|
+
from_hex('0xabc').should == 0xaabbccff
|
98
101
|
end
|
99
102
|
|
100
|
-
it "should allow setting opacity
|
103
|
+
it "should allow setting opacity explicitly" do
|
101
104
|
from_hex('0x0a6496', 0x64).should == @non_opaque
|
102
105
|
from_hex('#0a6496', 0x64).should == @non_opaque
|
106
|
+
from_hex('0xabc', 0xdd).should == 0xaabbccdd
|
107
|
+
from_hex('#abc', 0xdd).should == 0xaabbccdd
|
103
108
|
end
|
104
109
|
end
|
105
110
|
|
@@ -113,7 +118,7 @@ describe ChunkyPNG::Color do
|
|
113
118
|
html_color('SPRING_GREEN').should == 0x00ff7fff
|
114
119
|
end
|
115
120
|
|
116
|
-
it "should set the opacity level
|
121
|
+
it "should set the opacity level explicitly" do
|
117
122
|
html_color(:springgreen, 0xff).should == 0x00ff7fff
|
118
123
|
html_color(:springgreen, 0xaa).should == 0x00ff7faa
|
119
124
|
html_color(:springgreen, 0x00).should == 0x00ff7f00
|
Binary file
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chunky_png
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Willem van Bergen
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rake
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rspec
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -358,6 +363,7 @@ files:
|
|
358
363
|
- spec/resources/damaged_signature.png
|
359
364
|
- spec/resources/lines.png
|
360
365
|
- spec/resources/operations.png
|
366
|
+
- spec/resources/operations_border.png
|
361
367
|
- spec/resources/operations_grayscale.png
|
362
368
|
- spec/resources/partial_circles.png
|
363
369
|
- spec/resources/pixelstream.rgb
|
@@ -378,7 +384,6 @@ files:
|
|
378
384
|
homepage: http://wiki.github.com/wvanbergen/chunky_png
|
379
385
|
licenses:
|
380
386
|
- MIT
|
381
|
-
metadata: {}
|
382
387
|
post_install_message:
|
383
388
|
rdoc_options:
|
384
389
|
- --title
|
@@ -390,20 +395,22 @@ rdoc_options:
|
|
390
395
|
require_paths:
|
391
396
|
- lib
|
392
397
|
required_ruby_version: !ruby/object:Gem::Requirement
|
398
|
+
none: false
|
393
399
|
requirements:
|
394
400
|
- - ! '>='
|
395
401
|
- !ruby/object:Gem::Version
|
396
402
|
version: '0'
|
397
403
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
404
|
+
none: false
|
398
405
|
requirements:
|
399
406
|
- - ! '>='
|
400
407
|
- !ruby/object:Gem::Version
|
401
408
|
version: '0'
|
402
409
|
requirements: []
|
403
410
|
rubyforge_project:
|
404
|
-
rubygems_version:
|
411
|
+
rubygems_version: 1.8.23
|
405
412
|
signing_key:
|
406
|
-
specification_version:
|
413
|
+
specification_version: 3
|
407
414
|
summary: Pure ruby library for read/write, chunk-level access to PNG files
|
408
415
|
test_files:
|
409
416
|
- spec/chunky_png/canvas/adam7_interlacing_spec.rb
|
@@ -669,6 +676,7 @@ test_files:
|
|
669
676
|
- spec/resources/damaged_signature.png
|
670
677
|
- spec/resources/lines.png
|
671
678
|
- spec/resources/operations.png
|
679
|
+
- spec/resources/operations_border.png
|
672
680
|
- spec/resources/operations_grayscale.png
|
673
681
|
- spec/resources/partial_circles.png
|
674
682
|
- spec/resources/pixelstream.rgb
|
@@ -685,4 +693,3 @@ test_files:
|
|
685
693
|
- spec/resources/text_chunk.png
|
686
694
|
- spec/resources/ztxt_chunk.png
|
687
695
|
- spec/spec_helper.rb
|
688
|
-
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
YzUzNWM2NzJlMTZkMWE4ZTkwZDQ3ZWVmYWViYzg4YjQ0YTEyM2JiNw==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YzljODZlMWYxMWI5ZjQ5ZDVhNmRhMDlmNjRiMDY4OThhOTVmZGZlMw==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YTU4ZjZhMWQ4NDU0ZTU1MDMwNzdkZDQxMjMwMWQxNWE5NDljNmI5OWQ0NDNi
|
10
|
-
MDA2NmZlODIyY2Q4NjYxYTM1NDAzODQxYmNiMzI2NzU5MzI3ZTIzZTRlMWE2
|
11
|
-
YWNlMDVjYjJiM2QwMzc3YWE5ZDZlMGZkY2Y3OGI1ZDQ0YzFmOTU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YjQyY2RhNzdhMWUyMTY2M2RiMTNiN2MwMzdkY2U2MzAxODA4ZmM3NDI4NTM2
|
14
|
-
ZTM2MDc5ZDA5NmZlNzg5ZDc3YjYyNjdiMDYxMDQ1YjJiY2IxY2JhZTVjOTFi
|
15
|
-
ZjczMWY3MjA4NDhmZThhMTNlMWEzYjNhMTUxYWRiMmU3MWFmNzI=
|