gmagick 0.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.
@@ -0,0 +1,62 @@
1
+ #include "gmagick.h"
2
+
3
+ void
4
+ gum_check_image_exception(MagickWand *wand, MagickPassFail status) {
5
+ if (status != MagickPass) {
6
+ char *description;
7
+ ExceptionType severity;
8
+
9
+ description=MagickGetException(wand,&severity);
10
+ rb_raise(rb_eRuntimeError, "%s", description);
11
+ }
12
+ }
13
+
14
+ MagickWand*
15
+ gmu_get_image_wand(VALUE self) {
16
+ GmImage *ptr;
17
+ Data_Get_Struct(self, GmImage, ptr);
18
+ return ptr->wand;
19
+ }
20
+
21
+ char*
22
+ gmu_str2cstr(VALUE src, long *length) {
23
+ StringValue(src);
24
+ if (length) {
25
+ *length = RSTRING_LEN(src);
26
+ }
27
+ return RSTRING_PTR(src);
28
+ }
29
+
30
+ PixelWand*
31
+ gmu_get_pixel_wand(VALUE self) {
32
+ GmPixel *ptr;
33
+ Data_Get_Struct(self, GmPixel, ptr);
34
+ return ptr->wand;
35
+ }
36
+
37
+ DrawingWand*
38
+ gmu_get_drawing_wand(VALUE self) {
39
+ GmDrawing *ptr;
40
+ Data_Get_Struct(self, GmDrawing, ptr);
41
+ return ptr->wand;
42
+ }
43
+
44
+ PixelWand*
45
+ gmu_get_pixel_string_or_pixel(VALUE color_arg) {
46
+ PixelWand *pixel;
47
+ if (T_STRING == TYPE(color_arg)) {
48
+ pixel = NewPixelWand();
49
+ char *color = StringValuePtr(color_arg);
50
+ PixelSetColor(pixel, color);
51
+ } else {
52
+ pixel = gmu_get_pixel_wand(color_arg);
53
+ }
54
+ return pixel;
55
+ }
56
+
57
+ void
58
+ gmu_clear_pixel_string_or_pixel(VALUE pixel_arg, PixelWand* pixel) {
59
+ if (T_STRING == TYPE(pixel_arg)) {
60
+ DestroyPixelWand(pixel);
61
+ }
62
+ }
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gmagick/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gmagick"
8
+ spec.version = Gmagick::VERSION
9
+ spec.authors = ["aoyagikouhei"]
10
+ spec.email = ["aoyagi.kouhei@gmail.com"]
11
+ spec.description = %q{GraphicsMagick C extension}
12
+ spec.summary = %q{GraphicsMagick C extension}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.extensions << "ext/gmagick/extconf.rb"
26
+ end
@@ -0,0 +1,6 @@
1
+ require "gmagick/version"
2
+ require "gmagickn"
3
+
4
+ module Gmagick
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,3 @@
1
+ module Gmagick
2
+ VERSION = "0.0.1"
3
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,496 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gmagick do
4
+ it 'should have a version number' do
5
+ expect(Gmagick::VERSION).not_to be_nil
6
+ end
7
+ end
8
+
9
+ describe Gmagick::Image do
10
+ before(:all) do
11
+ if !File.exists?(DST_PATH)
12
+ Dir.mkdir(DST_PATH)
13
+ end
14
+ Dir::glob(DST_PATH + "/*.{jpg,png,gif}").each do |f|
15
+ File.delete(f)
16
+ end
17
+ end
18
+
19
+ it 'initialize and read' do
20
+ image = Gmagick::Image.new(DICE_PATH)
21
+ expect(image.width).to eq(200)
22
+ expect(image.height).to eq(150)
23
+ expect(image.format).to eq("PNG")
24
+ expect(image.count).to eq(1)
25
+
26
+ proc do
27
+ image = Gmagick::Image.new(DICE_PATH, 1)
28
+ end.should raise_error(ArgumentError, "wrong number of arguments (2 for 0 or 1)")
29
+
30
+ proc do
31
+ image = Gmagick::Image.new(1)
32
+ end.should raise_error(TypeError, "no implicit conversion of Fixnum into String")
33
+
34
+ proc do
35
+ image = Gmagick::Image.new(DICE_PATH+"a")
36
+ end.should raise_error(RuntimeError, /^Unable to open file/)
37
+ end
38
+
39
+ it 'read png image' do
40
+ image = Gmagick::Image.new
41
+ image.read(DICE_PATH)
42
+ expect(image.width).to eq(200)
43
+ expect(image.height).to eq(150)
44
+ expect(image.format).to eq("PNG")
45
+ expect(image.count).to eq(1)
46
+ expect(image.depth).to eq(8)
47
+ expect(image.colors).to eq(7127)
48
+ resolution = image.resolution
49
+ expect(resolution[0]).to eq(72.0)
50
+ expect(resolution[1]).to eq(72.0)
51
+ end
52
+
53
+ it 'read jpeg image' do
54
+ image = Gmagick::Image.new
55
+ image.read(FLOWER_PATH)
56
+ expect(image.width).to eq(240)
57
+ expect(image.height).to eq(214)
58
+ expect(image.format).to eq('JPEG')
59
+ expect(image.count).to eq(1)
60
+ end
61
+
62
+ it 'read gif image' do
63
+ image = Gmagick::Image.new
64
+ image.read(EARTH_PATH)
65
+ expect(image.width).to eq(200)
66
+ expect(image.height).to eq(200)
67
+ expect(image.format).to eq('GIF')
68
+ expect(image.count).to eq(44)
69
+ end
70
+
71
+ it 'read write blob' do
72
+ image = Gmagick::Image.new
73
+ image.read(DICE_PATH)
74
+ image2 = Gmagick::Image.new
75
+ image2.read_blob(image.write_blob)
76
+ expect(image2.width).to eq(200)
77
+ expect(image2.height).to eq(150)
78
+ expect(image2.format).to eq('PNG')
79
+ end
80
+
81
+ it 'read write file' do
82
+ image = Gmagick::Image.new(DICE_PATH)
83
+ image.write(DICE2_PATH)
84
+ image2 = Gmagick::Image.new(DICE2_PATH)
85
+ expect(image2.width).to eq(200)
86
+ expect(image2.height).to eq(150)
87
+ expect(image2.format).to eq("PNG")
88
+ expect(image2.count).to eq(1)
89
+ image2.write
90
+
91
+ proc do
92
+ image2.write(DICE2_PATH, 1)
93
+ end.should raise_error(ArgumentError, "wrong number of arguments (2 for 0 or 1)")
94
+
95
+ proc do
96
+ image2.write(1)
97
+ end.should raise_error(TypeError, "no implicit conversion of Fixnum into String")
98
+ end
99
+
100
+ it 'resize' do
101
+ image = Gmagick::Image.new(DICE_PATH)
102
+ image.resize(100, 75)
103
+ image.write(DICE2_PATH)
104
+ image2 = Gmagick::Image.new(DICE2_PATH)
105
+ expect(image2.width).to eq(100)
106
+ expect(image2.height).to eq(75)
107
+ expect(image2.format).to eq('PNG')
108
+ expect(image2.count).to eq(1)
109
+
110
+ proc do
111
+ image.resize(1, 2, 3, 4, 5)
112
+ end.should raise_error(ArgumentError, "wrong number of arguments (5 for 2 or 4)")
113
+
114
+ proc do
115
+ image.resize("1", "2")
116
+ end.should raise_error(TypeError, "no implicit conversion of String into Integer")
117
+ end
118
+
119
+ it 'resample' do
120
+ image = Gmagick::Image.new(DICE_PATH)
121
+ image.resample(400, 400)
122
+ image.write(DICE_RESAMPLE_PATH)
123
+
124
+ image2 = Gmagick::Image.new(DICE_RESAMPLE_PATH)
125
+ expect(image2.width).to eq(1111)
126
+ expect(image2.height).to eq(833)
127
+ expect(image2.format).to eq('PNG')
128
+ expect(image2.count).to eq(1)
129
+
130
+ proc do
131
+ image.resample(1, 2, 3, 4, 5)
132
+ end.should raise_error(ArgumentError, "wrong number of arguments (5 for 2 or 4)")
133
+
134
+ proc do
135
+ image.resample("1", "2")
136
+ end.should raise_error(TypeError, "no implicit conversion of String into Integer")
137
+ end
138
+
139
+ it 'rotate' do
140
+ image = Gmagick::Image.new(DICE_PATH)
141
+ pixel = Gmagick::Pixel.new("#00FF00")
142
+ image.rotate(pixel, 30)
143
+ image.write(DICE_ROTATE_PATH)
144
+
145
+ image = Gmagick::Image.new(DICE_PATH)
146
+ image.rotate("red", 30)
147
+ image.write(DICE_ROTATE2_PATH)
148
+ end
149
+
150
+ it 'draw' do
151
+ image = Gmagick::Image.new(DICE_PATH)
152
+ drawing = Gmagick::Drawing.new
153
+ pixel = Gmagick::Pixel.new("white")
154
+ drawing.fill_color = pixel
155
+ drawing.stroke_color = "black"
156
+ drawing.stroke_width = 3.0
157
+ drawing.round_rectangle(10, 10, 100, 100, 100, 100)
158
+ image.draw(drawing)
159
+ image.write(DICE_DRAW_PATH)
160
+ end
161
+
162
+ it 'flip' do
163
+ image = Gmagick::Image.new(DICE_PATH)
164
+ image.flip
165
+ image.write(DICE_FLIP_PATH)
166
+ image2 = Gmagick::Image.new(DICE_FLIP_PATH)
167
+ expect(image2.width).to eq(200)
168
+ expect(image2.height).to eq(150)
169
+ expect(image2.format).to eq("PNG")
170
+ expect(image2.count).to eq(1)
171
+ end
172
+
173
+ it 'flop' do
174
+ image = Gmagick::Image.new(DICE_PATH)
175
+ image.flop
176
+ image.write(DICE_FLOP_PATH)
177
+ image2 = Gmagick::Image.new(DICE_FLOP_PATH)
178
+ expect(image2.width).to eq(200)
179
+ expect(image2.height).to eq(150)
180
+ expect(image2.format).to eq("PNG")
181
+ expect(image2.count).to eq(1)
182
+ end
183
+
184
+ it 'crop' do
185
+ image = Gmagick::Image.new(DICE_PATH)
186
+ image.crop(50, 50, 30, 30)
187
+ image.write(DICE_CROP_PATH)
188
+ image2 = Gmagick::Image.new(DICE_CROP_PATH)
189
+ expect(image2.width).to eq(50)
190
+ expect(image2.height).to eq(50)
191
+ expect(image2.format).to eq("PNG")
192
+ expect(image2.count).to eq(1)
193
+ end
194
+
195
+ it 'set_format' do
196
+ image = Gmagick::Image.new(DICE_PATH)
197
+ image.format = "JPEG"
198
+ image2 = Gmagick::Image.new
199
+ image2.read_blob(image.write_blob)
200
+ expect(image2.width).to eq(200)
201
+ expect(image2.height).to eq(150)
202
+ expect(image2.format).to eq("JPEG")
203
+ expect(image2.count).to eq(1)
204
+ end
205
+
206
+ it 'border' do
207
+ image = Gmagick::Image.new(DICE_PATH)
208
+ image.border("blue", 4, 15)
209
+ image.write(DICE_BORDER_PATH)
210
+ image2 = Gmagick::Image.new(DICE_BORDER_PATH)
211
+ expect(image2.width).to eq(208)
212
+ expect(image2.height).to eq(180)
213
+ expect(image2.format).to eq("PNG")
214
+ expect(image2.count).to eq(1)
215
+ end
216
+
217
+ it 'frame' do
218
+ image = Gmagick::Image.new(DICE_PATH)
219
+ image.frame("silver", 20, 20, 5, 5)
220
+ image.write(DICE_FRAME_PATH)
221
+ image2 = Gmagick::Image.new(DICE_FRAME_PATH)
222
+ expect(image2.width).to eq(240)
223
+ expect(image2.height).to eq(190)
224
+ expect(image2.format).to eq("PNG")
225
+ expect(image2.count).to eq(1)
226
+ end
227
+
228
+ it 'frame' do
229
+ image = Gmagick::Image.new(DICE_PATH)
230
+ image.blur(8, 3)
231
+ image.write(DICE_BLUR_PATH)
232
+ image2 = Gmagick::Image.new(DICE_BLUR_PATH)
233
+ expect(image2.width).to eq(200)
234
+ expect(image2.height).to eq(150)
235
+ expect(image2.format).to eq("PNG")
236
+ expect(image2.count).to eq(1)
237
+ end
238
+
239
+ it 'swirl' do
240
+ image = Gmagick::Image.new(DICE_PATH)
241
+ image.swirl(180)
242
+ image.write(DICE_SWIRL_PATH)
243
+ image2 = Gmagick::Image.new(DICE_SWIRL_PATH)
244
+ expect(image2.width).to eq(200)
245
+ expect(image2.height).to eq(150)
246
+ expect(image2.format).to eq("PNG")
247
+ expect(image2.count).to eq(1)
248
+ end
249
+
250
+ it 'charcoal' do
251
+ image = Gmagick::Image.new(DICE_PATH)
252
+ image.charcoal(5, 0.2)
253
+ image.write(DICE_CHARCOAL_PATH)
254
+ image2 = Gmagick::Image.new(DICE_CHARCOAL_PATH)
255
+ expect(image2.width).to eq(200)
256
+ expect(image2.height).to eq(150)
257
+ expect(image2.format).to eq("PNG")
258
+ expect(image2.count).to eq(1)
259
+ end
260
+
261
+ it 'oil_paint' do
262
+ image = Gmagick::Image.new(DICE_PATH)
263
+ image.oil_paint(2.5)
264
+ image.write(DICE_OIL_PAINT_PATH)
265
+ image2 = Gmagick::Image.new(DICE_OIL_PAINT_PATH)
266
+ expect(image2.width).to eq(200)
267
+ expect(image2.height).to eq(150)
268
+ expect(image2.format).to eq("PNG")
269
+ expect(image2.count).to eq(1)
270
+ end
271
+
272
+ it 'cycle_colormap' do
273
+ image = Gmagick::Image.new(DICE_PATH)
274
+ image.cycle_colormap(100)
275
+ image.cycle_colormap(100)
276
+ image.cycle_colormap(100)
277
+ image.cycle_colormap(100)
278
+ image.write(DICE_CYCLE_COLORMAP_PATH)
279
+ image2 = Gmagick::Image.new(DICE_CYCLE_COLORMAP_PATH)
280
+ expect(image2.width).to eq(200)
281
+ expect(image2.height).to eq(150)
282
+ expect(image2.format).to eq("PNG")
283
+ expect(image2.count).to eq(1)
284
+ end
285
+
286
+ it 'solarize' do
287
+ image = Gmagick::Image.new(DICE_PATH)
288
+ image.solarize(100)
289
+ image.write(DICE_SOLARIZE_PATH)
290
+ image2 = Gmagick::Image.new(DICE_SOLARIZE_PATH)
291
+ expect(image2.width).to eq(200)
292
+ expect(image2.height).to eq(150)
293
+ expect(image2.format).to eq("PNG")
294
+ expect(image2.count).to eq(1)
295
+ end
296
+
297
+ it 'shear' do
298
+ image = Gmagick::Image.new(DICE_PATH)
299
+ image.shear("white", 5, 70)
300
+ image.write(DICE_SHEAR_PATH)
301
+ image2 = Gmagick::Image.new(DICE_SHEAR_PATH)
302
+ expect(image2.width).to eq(207)
303
+ expect(image2.height).to eq(332)
304
+ expect(image2.format).to eq("PNG")
305
+ expect(image2.count).to eq(1)
306
+ end
307
+ end
308
+
309
+ describe Gmagick::Pixel do
310
+ it 'initialize' do
311
+ pixel = Gmagick::Pixel.new
312
+ expect(pixel).not_to be_nil
313
+ pixel = Gmagick::Pixel.new("#000000")
314
+ expect(pixel).not_to be_nil
315
+ expect(pixel.color).to eq("0,0,0")
316
+ pixel.color = "red"
317
+ expect(pixel.color).to eq("255,0,0")
318
+
319
+ proc do
320
+ pixel = Gmagick::Pixel.new(1, 2)
321
+ end.should raise_error(ArgumentError, "wrong number of arguments (2 for 0 or 1)")
322
+
323
+ proc do
324
+ pixel = Gmagick::Pixel.new(1)
325
+ end.should raise_error(TypeError, "no implicit conversion of Fixnum into String")
326
+ end
327
+
328
+ it 'color_count' do
329
+ pixel = Gmagick::Pixel.new("#000000")
330
+ pixel.color_count = 100
331
+ expect(pixel.color_count).to eq(100)
332
+ end
333
+ end
334
+
335
+ describe Gmagick::Drawing do
336
+ it 'initialize' do
337
+ drawing = Gmagick::Drawing.new
338
+ end
339
+
340
+ it 'fill_color' do
341
+ drawing = Gmagick::Drawing.new
342
+ drawing.fill_color = "red"
343
+ pixel = drawing.fill_color
344
+ expect(pixel.color).to eq("255,0,0")
345
+ pixel.color = "blue"
346
+ pixel2 = drawing.fill_color
347
+ expect(pixel.color).to eq("0,0,255")
348
+ end
349
+
350
+ it 'fill_opacity' do
351
+ drawing = Gmagick::Drawing.new
352
+ drawing.fill_opacity = 0.5
353
+ expect(drawing.fill_opacity.round(1)).to eq(0.5)
354
+ end
355
+
356
+ it 'stroke_color' do
357
+ drawing = Gmagick::Drawing.new
358
+ drawing.stroke_color = "red"
359
+ pixel = drawing.stroke_color
360
+ expect(pixel.color).to eq("255,0,0")
361
+ pixel.color = "blue"
362
+ pixel2 = drawing.stroke_color
363
+ expect(pixel.color).to eq("0,0,255")
364
+ end
365
+
366
+ it 'stroke_opacity' do
367
+ drawing = Gmagick::Drawing.new
368
+ drawing.stroke_opacity = 0.5
369
+ expect(drawing.stroke_opacity.round(1)).to eq(0.5)
370
+ end
371
+
372
+ it 'stroke_width' do
373
+ drawing = Gmagick::Drawing.new
374
+ drawing.stroke_width = 10
375
+ expect(drawing.stroke_width).to eq(10)
376
+ end
377
+
378
+ it 'font' do
379
+ drawing = Gmagick::Drawing.new
380
+ drawing.font = "system"
381
+ expect(drawing.font).to eq("system")
382
+ end
383
+
384
+ it 'font_family' do
385
+ drawing = Gmagick::Drawing.new
386
+ drawing.font_family = "system"
387
+ expect(drawing.font_family).to eq("system")
388
+ end
389
+
390
+ it 'font_size' do
391
+ drawing = Gmagick::Drawing.new
392
+ drawing.font_size = 10
393
+ expect(drawing.font_size).to eq(10)
394
+ end
395
+
396
+ it 'font_stretch' do
397
+ drawing = Gmagick::Drawing.new
398
+ drawing.font_stretch = 10
399
+ expect(drawing.font_stretch).to eq(10)
400
+ end
401
+
402
+ it 'font_style' do
403
+ drawing = Gmagick::Drawing.new
404
+ drawing.font_style = 10
405
+ expect(drawing.font_style).to eq(10)
406
+ end
407
+
408
+ it 'font_weight' do
409
+ drawing = Gmagick::Drawing.new
410
+ drawing.font_weight = 10
411
+ expect(drawing.font_weight).to eq(10)
412
+ end
413
+
414
+ it 'text_decoration' do
415
+ drawing = Gmagick::Drawing.new
416
+ drawing.text_decoration = 2
417
+ expect(drawing.text_decoration).to eq(2)
418
+ end
419
+
420
+ it 'text_encoding' do
421
+ drawing = Gmagick::Drawing.new
422
+ drawing.text_encoding = "UTF-8"
423
+ expect(drawing.text_encoding).to eq("UTF-8")
424
+ end
425
+
426
+ it 'annotation' do
427
+ execute_draw(DRAW_ANNOTATION_PATH) do |drawing|
428
+ drawing.font = "Osaka"
429
+ drawing.font_style = 1
430
+ drawing.font_size = 32
431
+ drawing.font_weight = 400
432
+ drawing.fill_color = "black"
433
+ drawing.stroke_color = "black"
434
+ drawing.text_encoding = "UTF-8"
435
+ drawing.annotation(30, 30, "Hello World")
436
+ end
437
+ end
438
+
439
+ it 'arc' do
440
+ execute_draw(DRAW_ARC_PATH) do |drawing|
441
+ drawing.fill_color = "black"
442
+ drawing.stroke_color = "red"
443
+ drawing.stroke_width = 3
444
+ drawing.arc(10, 10, 100, 100, 0, 180)
445
+ end
446
+ end
447
+
448
+ it 'circle' do
449
+ execute_draw(DRAW_CIRCLE_PATH) do |drawing|
450
+ drawing.fill_color = "black"
451
+ drawing.stroke_color = "red"
452
+ drawing.stroke_width = 3
453
+ drawing.circle(50, 50, 1, 80)
454
+ end
455
+ end
456
+
457
+ it 'ellipse' do
458
+ execute_draw(DRAW_ELLIPSE_PATH) do |drawing|
459
+ drawing.fill_color = "black"
460
+ drawing.stroke_color = "red"
461
+ drawing.stroke_width = 3
462
+ drawing.ellipse(100, 75, 50, 50, 0, 0)
463
+ end
464
+ end
465
+
466
+ it 'line' do
467
+ execute_draw(DRAW_LINE_PATH) do |drawing|
468
+ drawing.fill_color = "black"
469
+ drawing.stroke_color = "red"
470
+ drawing.stroke_width = 3
471
+ drawing.line(10, 10, 50, 50)
472
+ end
473
+ end
474
+
475
+ it 'point' do
476
+ execute_draw(DRAW_POINT_PATH) do |drawing|
477
+ drawing.fill_color = "black"
478
+ drawing.stroke_color = "red"
479
+ drawing.stroke_width = 3
480
+ drawing.point(10, 50)
481
+ drawing.point(11, 50)
482
+ drawing.point(12, 50)
483
+ end
484
+ end
485
+
486
+ it 'rectangle' do
487
+ execute_draw(DRAW_RECTANGLE_PATH) do |drawing|
488
+ drawing.fill_color = "black"
489
+ drawing.stroke_color = "red"
490
+ drawing.stroke_width = 3
491
+ drawing.rectangle(50, 20, 130, 80)
492
+ drawing.rotate(30)
493
+ drawing.scale(1, 2)
494
+ end
495
+ end
496
+ end