rmagick4j 0.3.1-java
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/lib/RMagick.jar +0 -0
- data/lib/magick4j.jar +0 -0
- data/lib/rmagick4j/rmagick4j.rb +378 -0
- metadata +44 -0
data/lib/RMagick.jar
ADDED
Binary file
|
data/lib/magick4j.jar
ADDED
Binary file
|
@@ -0,0 +1,378 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'magick4j.jar'
|
3
|
+
require 'observer'
|
4
|
+
|
5
|
+
module Magick
|
6
|
+
|
7
|
+
Magick4J = Java::magick4j
|
8
|
+
RMagick4J = Java::rmagick4j
|
9
|
+
|
10
|
+
class Draw
|
11
|
+
|
12
|
+
def annotate(img, width, height, x, y, text, &add)
|
13
|
+
instance_eval &add if add
|
14
|
+
@draw.annotate(img._image, width, height, x, y, text)
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def draw(image)
|
19
|
+
@draw.clone.draw(image._image, Magick4J.CommandParser.parse(@primitives))
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def fill= fill
|
24
|
+
@draw.setFill(Magick4J.ColorDatabase.queryDefault(fill))
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def font_weight= font_weight
|
29
|
+
font_weight = {BoldWeight => 700, NormalWeight => 400}[font_weight]
|
30
|
+
@draw.setFontWeight(font_weight)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_type_metrics(*args)
|
34
|
+
raise ArgumentError.new('wrong number of arguments (#{args.length})') if not (1..2) === args.length
|
35
|
+
string = args.last
|
36
|
+
image = args.first._image if args.length == 2
|
37
|
+
jmetrics = @draw.getTypeMetrics(string, image)
|
38
|
+
metrics = TypeMetric.new
|
39
|
+
metrics.ascent = jmetrics.getAscent
|
40
|
+
metrics.descent = jmetrics.getDescent
|
41
|
+
metrics.height = jmetrics.getHeight
|
42
|
+
metrics.max_advance = jmetrics.getMaxAdvance
|
43
|
+
metrics.width = jmetrics.getWidth
|
44
|
+
metrics
|
45
|
+
end
|
46
|
+
|
47
|
+
def font= font
|
48
|
+
# TODO
|
49
|
+
end
|
50
|
+
|
51
|
+
def gravity= gravity
|
52
|
+
@draw.setGravity(gravity._val)
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize
|
56
|
+
# Docs say that you can initialize with a block, but it doesn't really work because it inits an ImageInfo not a DrawInfo.
|
57
|
+
# instance_eval &add if add
|
58
|
+
@draw = Magick4J.DrawInfo.new
|
59
|
+
@primitives = ''
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
@primitives
|
64
|
+
end
|
65
|
+
|
66
|
+
def pointsize= pointsize
|
67
|
+
@draw.setPointSize(pointsize)
|
68
|
+
end
|
69
|
+
|
70
|
+
def primitive primitive
|
71
|
+
# TODO Concat in a string like they do, then use helper to parse later
|
72
|
+
@primitives << "\n" unless @primitives.empty?
|
73
|
+
@primitives << primitive
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
|
+
def rotation= rotation
|
78
|
+
@draw.rotate(rotation)
|
79
|
+
self
|
80
|
+
end
|
81
|
+
|
82
|
+
def stroke= stroke
|
83
|
+
@draw.setStroke(Magick4J.ColorDatabase.queryDefault(stroke))
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
class Enum
|
90
|
+
|
91
|
+
def self.def_val(name, val)
|
92
|
+
enum = new(name, val)
|
93
|
+
Magick.const_set(name, enum)
|
94
|
+
end
|
95
|
+
|
96
|
+
def initialize(name, val)
|
97
|
+
@name = name
|
98
|
+
@val = val
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_i
|
102
|
+
@val.ordinal
|
103
|
+
end
|
104
|
+
|
105
|
+
def _val
|
106
|
+
@val
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
class GradientFill
|
112
|
+
|
113
|
+
def fill(image)
|
114
|
+
@fill.fill(image._image)
|
115
|
+
end
|
116
|
+
|
117
|
+
def initialize(x1, y1, x2, y2, start_color, end_color)
|
118
|
+
@fill = Magick4J.GradientFill.new(x1, y1, x2, y2, Magick4J.ColorDatabase.queryDefault(start_color), Magick4J.ColorDatabase.queryDefault(end_color))
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
class Image
|
124
|
+
|
125
|
+
def self.from_blob(blob, &add)
|
126
|
+
# TODO Use info somehow
|
127
|
+
info = Info.new(&add)
|
128
|
+
# TODO multiple images in file
|
129
|
+
[Image.new(Magick4J.MagickImage.fromBlob(RMagick4J.JRubyUtil.toByteArray(blob)))]
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.read(file, &add)
|
133
|
+
[Image.new(file, &add)]
|
134
|
+
end
|
135
|
+
|
136
|
+
def blur_image(radius=0.0, sigma=1.0)
|
137
|
+
# Swap order on purpose. I wanted them the other way around in Magick4J.
|
138
|
+
Image.new(@image.blurred(sigma, radius))
|
139
|
+
end
|
140
|
+
|
141
|
+
def columns
|
142
|
+
@image.getWidth
|
143
|
+
end
|
144
|
+
|
145
|
+
def composite(*args)
|
146
|
+
# image, x, y, composite_op
|
147
|
+
args[0] = args[0]._image
|
148
|
+
args.map! {|arg| arg.is_a?(Enum) ? arg._val : arg}
|
149
|
+
Image.new(@image.composited(*args))
|
150
|
+
end
|
151
|
+
|
152
|
+
def crop(x, y, width, height)
|
153
|
+
Image.new(@image.cropped(x, y, width, height))
|
154
|
+
end
|
155
|
+
|
156
|
+
def display
|
157
|
+
@image.display
|
158
|
+
self
|
159
|
+
end
|
160
|
+
|
161
|
+
def format
|
162
|
+
@image.getFormat
|
163
|
+
end
|
164
|
+
|
165
|
+
def format= format
|
166
|
+
@image.setFormat(format)
|
167
|
+
self
|
168
|
+
end
|
169
|
+
|
170
|
+
def flip!
|
171
|
+
@image.flip
|
172
|
+
self
|
173
|
+
end
|
174
|
+
|
175
|
+
def _image
|
176
|
+
@image
|
177
|
+
end
|
178
|
+
|
179
|
+
def initialize(*args, &add)
|
180
|
+
# TODO Only use new as defined in the RMagick docs. Use allocate and other methods otherwise?
|
181
|
+
info = Info.new(&add)
|
182
|
+
if args.length == 1
|
183
|
+
if args[0].is_a? String
|
184
|
+
# TODO Respect Dir.getwd
|
185
|
+
name = args[0]
|
186
|
+
@image = Magick4J.ImageDatabase.createDefault(name, info._info) || Magick4J.MagickImage.new(java.io.File.new(name))
|
187
|
+
else
|
188
|
+
@image = args[0]
|
189
|
+
end
|
190
|
+
else
|
191
|
+
@image = Magick4J.MagickImage.new(args[0], args[1], info._info)
|
192
|
+
if args.length == 3
|
193
|
+
args[2].fill(self)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def matte= matte
|
199
|
+
@image.setMatte(matte)
|
200
|
+
end
|
201
|
+
|
202
|
+
def quantize(number_colors=256, colorspace=RGBColorspace, dither=true, tree_depth=0, measure_error=false)
|
203
|
+
Image.new(@image.quantized(number_colors, colorspace._val, dither, tree_depth, measure_error))
|
204
|
+
end
|
205
|
+
|
206
|
+
def raise(width=6, height=6, raise=true)
|
207
|
+
Image.new(@image.raised(width, height, raise))
|
208
|
+
end
|
209
|
+
|
210
|
+
def resize(scale_factor)
|
211
|
+
Image.new(@image.resized(scale_factor))
|
212
|
+
end
|
213
|
+
|
214
|
+
def rotate(scale_factor)
|
215
|
+
Image.new(@image.rotated(scale_factor))
|
216
|
+
end
|
217
|
+
|
218
|
+
def rows
|
219
|
+
@image.getHeight
|
220
|
+
end
|
221
|
+
|
222
|
+
def to_blob(&add)
|
223
|
+
# TODO Use info.
|
224
|
+
info = Info.new(&add)
|
225
|
+
@image.setFormat(info.format) if info.format
|
226
|
+
RMagick4J.JRubyUtil.toString(@image.toBlob)
|
227
|
+
end
|
228
|
+
|
229
|
+
def write(file, &add)
|
230
|
+
# TODO I'm having trouble finding out how this info is used, so I'll skip using it for now.
|
231
|
+
info = Info.new(&add)
|
232
|
+
# TODO Resolve pwd as needed
|
233
|
+
@image.write(file)
|
234
|
+
self
|
235
|
+
end
|
236
|
+
|
237
|
+
class Info
|
238
|
+
|
239
|
+
# TODO Replace with call to Java, or is this the better way? Should it be converted to the Java version only later?
|
240
|
+
def background_color= background_color
|
241
|
+
@info.setBackgroundColor(Magick4J.ColorDatabase.queryDefault(background_color))
|
242
|
+
end
|
243
|
+
|
244
|
+
attr_accessor :format
|
245
|
+
|
246
|
+
def _info
|
247
|
+
@info
|
248
|
+
end
|
249
|
+
|
250
|
+
def initialize(&add)
|
251
|
+
@info = Magick4J.ImageInfo.new
|
252
|
+
instance_eval &add if add
|
253
|
+
end
|
254
|
+
|
255
|
+
def size= size
|
256
|
+
size = Geometry.from_s(size) if size.is_a? String
|
257
|
+
geometry = Magick4J.Geometry.new
|
258
|
+
geometry.setWidth(size.width)
|
259
|
+
geometry.setHeight(size.height)
|
260
|
+
@info.setSize(geometry)
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
class ImageList < Array
|
268
|
+
|
269
|
+
def to_blob(&add)
|
270
|
+
# TODO Support lists.
|
271
|
+
first.to_blob(&add)
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
276
|
+
class TypeMetric
|
277
|
+
|
278
|
+
attr_accessor :ascent, :descent, :height, :max_advance, :width
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
|
283
|
+
# Enums
|
284
|
+
|
285
|
+
class CompositeOperator < Enum
|
286
|
+
def_val :CopyOpacityCompositeOp, Magick4J.CompositeOperator::COPY_OPACITY
|
287
|
+
def_val :OverCompositeOp, Magick4J.CompositeOperator::OVER
|
288
|
+
end
|
289
|
+
|
290
|
+
class GravityType < Enum
|
291
|
+
def_val :CenterGravity, Magick4J.Gravity::CENTER
|
292
|
+
def_val :EastGravity, Magick4J.Gravity::EAST
|
293
|
+
def_val :ForgetGravity, Magick4J.Gravity::FORGET
|
294
|
+
def_val :NorthEastGravity, Magick4J.Gravity::NORTH_EAST
|
295
|
+
def_val :NorthGravity, Magick4J.Gravity::NORTH
|
296
|
+
def_val :NorthWestGravity, Magick4J.Gravity::NORTH_WEST
|
297
|
+
def_val :SouthEastGravity, Magick4J.Gravity::SOUTH_EAST
|
298
|
+
def_val :SouthGravity, Magick4J.Gravity::SOUTH
|
299
|
+
def_val :SouthWestGravity, Magick4J.Gravity::SOUTH_WEST
|
300
|
+
def_val :WestGravity, Magick4J.Gravity::WEST
|
301
|
+
end
|
302
|
+
|
303
|
+
class ColorspaceType < Enum
|
304
|
+
def_val :GRAYColorspace, Magick4J.Colorspace::GRAY
|
305
|
+
def_val :RGBColorspace, Magick4J.Colorspace::RGB
|
306
|
+
def_val :UndefinedColorspace, Magick4J.Colorspace::Undefined
|
307
|
+
end
|
308
|
+
|
309
|
+
|
310
|
+
# Simple hack Enums.
|
311
|
+
# TODO All these need changed to the official way used above.
|
312
|
+
|
313
|
+
@@enumVal = 1
|
314
|
+
def self.nextVal
|
315
|
+
@@enumVal = @@enumVal + 1
|
316
|
+
end
|
317
|
+
|
318
|
+
LeftAlign = nextVal
|
319
|
+
RightAlign = nextVal
|
320
|
+
CenterAlign = nextVal
|
321
|
+
StartAnchor = nextVal
|
322
|
+
MiddleAnchor = nextVal
|
323
|
+
EndAnchor = nextVal
|
324
|
+
NoDecoration = nextVal
|
325
|
+
UnderlineDecoration = nextVal
|
326
|
+
OverlineDecoration = nextVal
|
327
|
+
LineThroughDecoration = nextVal
|
328
|
+
|
329
|
+
AnyWeight = nextVal
|
330
|
+
NormalWeight = nextVal
|
331
|
+
BoldWeight = nextVal
|
332
|
+
BolderWeight = nextVal
|
333
|
+
LighterWeight = nextVal
|
334
|
+
|
335
|
+
PointMethod = nextVal
|
336
|
+
ReplaceMethod = nextVal
|
337
|
+
FloodfillMethod = nextVal
|
338
|
+
FillToBorderMethod = nextVal
|
339
|
+
ResetMethod = nextVal
|
340
|
+
NormalStretch = nextVal
|
341
|
+
UltraCondensedStretch = nextVal
|
342
|
+
ExtraCondensedStretch = nextVal
|
343
|
+
CondensedStretch = nextVal
|
344
|
+
SemiCondensedStretch = nextVal
|
345
|
+
SemiExpandedStretch = nextVal
|
346
|
+
ExpandedStretch = nextVal
|
347
|
+
ExtraExpandedStretch = nextVal
|
348
|
+
UltraExpandedStretch = nextVal
|
349
|
+
AnyStretch = nextVal
|
350
|
+
NormalStyle = nextVal
|
351
|
+
ItalicStyle = nextVal
|
352
|
+
ObliqueStyle = nextVal
|
353
|
+
AnyStyle = nextVal
|
354
|
+
|
355
|
+
# ColorspaceType constants
|
356
|
+
# DEF_ENUM(ColorspaceType)
|
357
|
+
TransparentColorspace = nextVal
|
358
|
+
OHTAColorspace = nextVal
|
359
|
+
XYZColorspace = nextVal
|
360
|
+
YCbCrColorspace = nextVal
|
361
|
+
YCCColorspace = nextVal
|
362
|
+
YIQColorspace = nextVal
|
363
|
+
YPbPrColorspace = nextVal
|
364
|
+
YUVColorspace = nextVal
|
365
|
+
CMYKColorspace = nextVal
|
366
|
+
SRGBColorspace = nextVal
|
367
|
+
HSLColorspace = nextVal
|
368
|
+
HWBColorspace = nextVal
|
369
|
+
HSBColorspace = nextVal # IM 6.0.0
|
370
|
+
CineonLogRGBColorspace = nextVal # GM 1.2
|
371
|
+
LABColorspace = nextVal # GM 1.2
|
372
|
+
Rec601LumaColorspace = nextVal # GM 1.2 && IM 6.2.2
|
373
|
+
Rec601YCbCrColorspace = nextVal # GM 1.2 && IM 6.2.2
|
374
|
+
Rec709LumaColorspace = nextVal # GM 1.2 && IM 6.2.2
|
375
|
+
Rec709YCbCrColorspace = nextVal # GM 1.2 && IM 6.2.2
|
376
|
+
LogColorspace = nextVal # IM 6.2.3
|
377
|
+
|
378
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
cert_chain:
|
3
|
+
rubygems_version: 0.9.1
|
4
|
+
description: RMagick4J is a JRuby back end to support the RMagick library. It bundles
|
5
|
+
a Java library called Magick4J that implements ImageMagick and some RMagick native
|
6
|
+
functionality.
|
7
|
+
version: !ruby/object:Gem::Version
|
8
|
+
version: 0.3.1
|
9
|
+
requirements: []
|
10
|
+
test_files: []
|
11
|
+
bindir: bin
|
12
|
+
email: jruby-extras-devel@rubyforge.org
|
13
|
+
autorequire:
|
14
|
+
extensions: []
|
15
|
+
summary: RMagick4J is a JRuby back end for RMagick.
|
16
|
+
post_install_message:
|
17
|
+
homepage: http://rubyforge.org/projects/jruby-extras/
|
18
|
+
dependencies: []
|
19
|
+
has_rdoc: false
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
version:
|
22
|
+
requirements:
|
23
|
+
- - '>'
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 0.0.0
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
signing_key:
|
29
|
+
name: rmagick4j
|
30
|
+
executables: []
|
31
|
+
rdoc_options: []
|
32
|
+
files:
|
33
|
+
- lib/RMagick.jar
|
34
|
+
- lib/magick4j.jar
|
35
|
+
- lib/rmagick4j
|
36
|
+
- lib/rmagick4j/rmagick4j.rb
|
37
|
+
platform: java
|
38
|
+
rubyforge_project: jruby-extras
|
39
|
+
date: 2007-04-02 07:00:00 +00:00
|
40
|
+
authors:
|
41
|
+
- Tom Palmer
|
42
|
+
extra_rdoc_files: []
|
43
|
+
specification_version: 1
|
44
|
+
default_executable:
|