Module: Magick

Defined in:
lib/rvg/rvg.rb,
lib/rvg/misc.rb,
lib/rvg/misc.rb,
lib/rvg/misc.rb,
lib/rvg/text.rb,
lib/rvg/paint.rb,
lib/rvg/units.rb,
lib/rvg/clippath.rb,
lib/rvg/pathdata.rb,
lib/rvg/stylable.rb,
lib/rvg/container.rb,
lib/rvg/deep_equal.rb,
lib/rmagick/version.rb,
lib/rvg/describable.rb,
lib/rvg/stretchable.rb,
lib/rmagick_internal.rb,
lib/rvg/embellishable.rb,
lib/rvg/transformable.rb,
ext/RMagick/rmmain.c

Overview

– $Id: transformable.rb,v 1.5 2009/02/28 23:52:28 rmagick Exp $ Copyright © 2009 Timothy P. Hunter ++

Defined Under Namespace

Modules: IPTC Classes: DestroyedImageError, Draw, Enum, FatalImageMagickError, Geometry, GeometryValue, GradientFill, HatchFill, Image, ImageList, ImageMagickError, KernelInfo, OptionalMethodArguments, Pixel, RVG, SolidFill, TextureFill

Constant Summary collapse

VERSION =
'5.2.0'
MIN_RUBY_VERSION =
'2.3.0'
MIN_IM_VERSION =
'6.7.7'
IMAGEMAGICK_VERSION =
Magick::Magick_version.split[1].split('-').first
PercentGeometry =
GeometryValue.new(:PercentGeometry, 1).freeze
AspectGeometry =
GeometryValue.new(:AspectGeometry, 2).freeze
LessGeometry =
GeometryValue.new(:LessGeometry, 3).freeze
GreaterGeometry =
GeometryValue.new(:GreaterGeometry, 4).freeze
AreaGeometry =
GeometryValue.new(:AreaGeometry, 5).freeze
MinimumGeometry =
GeometryValue.new(:MinimumGeometry, 6).freeze
Magick_version =
str
Version =
str
Long_version =
str
Magick_features =
features

Class Method Summary collapse

Class Method Details

.colorsArray<Magick::Color> .colors {|colorinfo| ... } ⇒ Object

If called with the optional block, iterates over the colors, otherwise returns an array of Color objects.

Overloads:

  • .colorsArray<Magick::Color>

    Returns the array of Color.

    Returns:

    • (Array<Magick::Color>)

      the array of Color

  • .colors {|colorinfo| ... } ⇒ Object

    Yields:

    • (colorinfo)

    Yield Parameters:

    • colorinfo (Magick::Color)

      the color



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/RMagick/rmagick.c', line 44

VALUE
Magick_colors(VALUE class)
{
    const ColorInfo **color_info_list;
    size_t number_colors, x;
    VALUE ary;
    ExceptionInfo *exception;

    exception = AcquireExceptionInfo();

    color_info_list = GetColorInfoList("*", &number_colors, exception);
    CHECK_EXCEPTION();
    DestroyExceptionInfo(exception);


    if (rb_block_given_p())
    {
        for (x = 0; x < number_colors; x++)
        {
            rb_rescue(rm_yield_body, Import_ColorInfo(color_info_list[x]), rm_yield_handle_exception, (VALUE)color_info_list);
        }
        magick_free((void *)color_info_list);
        return class;
    }
    else
    {
        ary = rb_ary_new2((long) number_colors);
        for (x = 0; x < number_colors; x++)
        {
            rb_ary_push(ary, Import_ColorInfo(color_info_list[x]));
        }

        magick_free((void *)color_info_list);
        RB_GC_GUARD(ary);
        return ary;
    }
}

.fontsArray<Magick::Font> .fonts {|fontinfo| ... } ⇒ Object

If called with the optional block, iterates over the fonts, otherwise returns an array of Font objects.

Overloads:

  • .fontsArray<Magick::Font>

    Returns the array of Font.

    Returns:

    • (Array<Magick::Font>)

      the array of Font

  • .fonts {|fontinfo| ... } ⇒ Object

    Yields:

    • (fontinfo)

    Yield Parameters:

    • fontinfo (Magick::Font)

      the font



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'ext/RMagick/rmagick.c', line 95

VALUE
Magick_fonts(VALUE class)
{
    const TypeInfo **type_info;
    size_t number_types, x;
    VALUE ary;
    ExceptionInfo *exception;

    exception = AcquireExceptionInfo();
    type_info = GetTypeInfoList("*", &number_types, exception);
    CHECK_EXCEPTION();
    DestroyExceptionInfo(exception);

    if (rb_block_given_p())
    {
        for (x = 0; x < number_types; x++)
        {
            rb_rescue(rm_yield_body, Import_TypeInfo((const TypeInfo *)type_info[x]), rm_yield_handle_exception, (VALUE)type_info);
        }
        magick_free((void *)type_info);
        return class;
    }
    else
    {
        ary = rb_ary_new2((long)number_types);
        for (x = 0; x < number_types; x++)
        {
            rb_ary_push(ary, Import_TypeInfo((const TypeInfo *)type_info[x]));
        }
        magick_free((void *)type_info);
        RB_GC_GUARD(ary);
        return ary;
    }

}

.formatsHash .formats {|k, v| ... } ⇒ Magick

Describes the image formats supported by ImageMagick. If the optional block is present, calls the block once for each image format. The first argument, k, is the format name. The second argument, v, is the properties string described below.

  • B is “*” if the format has native blob support, or “ ” otherwise.

  • R is “r” if ImageMagick can read that format, or “-” otherwise.

  • W is “w” if ImageMagick can write that format, or “-” otherwise.

  • A is “+” if the format supports multi-image files, or “-” otherwise.

Examples:

p Magick.formats
=> {"3FR"=>" r-+", "3G2"=>" r-+", "3GP"=>" r-+", "A"=>"*rw+",
...

Overloads:

  • .formatsHash

    Returns the formats hash.

    Returns:

    • (Hash)

      the formats hash

  • .formats {|k, v| ... } ⇒ Magick

    Yields:

    • (k, v)

    Yield Parameters:

    • k (String)

      the format name

    • v (String)

      the properties string

    Returns:



54
55
56
57
58
59
60
61
62
63
# File 'lib/rmagick_internal.rb', line 54

def formats
  formats = init_formats

  if block_given?
    formats.each { |k, v| yield k, v }
    self
  else
    formats
  end
end

.init_formatsHash

Build the @@formats hash. The hash keys are image formats. The hash values specify the format “mode string”, i.e. a description of what ImageMagick can do with that format. The mode string is in the form “BRWA”, where

  • “B” is “*” if the format has native blob support, or “ ” otherwise.

  • “R” is “r” if ImageMagick can read that format, or “-” otherwise.

  • “W” is “w” if ImageMagick can write that format, or “-” otherwise.

  • “A” is “+” if the format supports multi-image files, or “-” otherwise.

Returns:

  • (Hash)

    the formats hash.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'ext/RMagick/rmagick.c', line 172

VALUE
Magick_init_formats(VALUE class ATTRIBUTE_UNUSED)
{
    const MagickInfo **magick_info;
    size_t number_formats, x;
    VALUE formats;
    ExceptionInfo *exception;

    formats = rb_hash_new();

    // IM 6.1.3 added an exception argument to GetMagickInfoList
    exception = AcquireExceptionInfo();
    magick_info = GetMagickInfoList("*", &number_formats, exception);
    CHECK_EXCEPTION();
    DestroyExceptionInfo(exception);


    for (x = 0; x < number_formats; x++)
    {
        rb_hash_aset(formats,
                     rb_str_new2(magick_info[x]->name),
                     MagickInfo_to_format((const MagickInfo *)magick_info[x]));
    }
    magick_free((void *)magick_info);
    RB_GC_GUARD(formats);
    return formats;
}

.limit_resource(resource) ⇒ Numeric .limit_resource(resource, limit) ⇒ Numeric

Get/set resource limits. If a limit is specified the old limit is set to the new value. Either way the current/old limit is returned.

Overloads:

  • .limit_resource(resource) ⇒ Numeric

    Get resource limits.

    Parameters:

    • resource (String, Symbol)

      the type of resource

  • .limit_resource(resource, limit) ⇒ Numeric

    Set resource limits.

    Parameters:

    • resource (String, Symbol)

      the type of resource

    • limit (Numeric)

      the new limit number

Returns:

  • (Numeric)

    the old limit.



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'ext/RMagick/rmagick.c', line 216

VALUE
Magick_limit_resource(int argc, VALUE *argv, VALUE class)
{
    VALUE resource, limit;
    ResourceType res = UndefinedResource;
    char *str;
    ID id;
    unsigned long cur_limit;

    rb_scan_args(argc, argv, "11", &resource, &limit);

    switch (TYPE(resource))
    {
        case T_NIL:
            return class;

        case T_SYMBOL:
            id = (ID)SYM2ID(resource);
            if (id == rb_intern("area"))
            {
                res = AreaResource;
            }
            else if (id == rb_intern("memory"))
            {
                res = MemoryResource;
            }
            else if (id == rb_intern("map"))
            {
                res = MapResource;
            }
            else if (id == rb_intern("disk"))
            {
                res = DiskResource;
            }
            else if (id == rb_intern("file"))
            {
                res = FileResource;
            }
            else if (id == rb_intern("time"))
            {
                res = TimeResource;
            }
            else
            {
                rb_raise(rb_eArgError, "unknown resource: `:%s'", rb_id2name(id));
            }
            break;

        default:
            str = StringValueCStr(resource);
            if (*str == '\0')
            {
                return class;
            }
            else if (rm_strcasecmp("area", str) == 0)
            {
                res = AreaResource;
            }
            else if (rm_strcasecmp("memory", str) == 0)
            {
                res = MemoryResource;
            }
            else if (rm_strcasecmp("map", str) == 0)
            {
                res = MapResource;
            }
            else if (rm_strcasecmp("disk", str) == 0)
            {
                res = DiskResource;
            }
            else if (rm_strcasecmp("file", str) == 0)
            {
                res = FileResource;
            }
            else if (rm_strcasecmp("time", str) == 0)
            {
                res = TimeResource;
            }
            else
            {
                rb_raise(rb_eArgError, "unknown resource: `%s'", str);
            }
            break;
    }

    RB_GC_GUARD(resource);

    cur_limit = GetMagickResourceLimit(res);

    if (argc > 1)
    {
        SetMagickResourceLimit(res, (MagickSizeType)NUM2ULONG(limit));
    }

    RB_GC_GUARD(limit);

    return ULONG2NUM(cur_limit);
}

.set_cache_threshold(threshold) ⇒ Object

Set the amount of free memory allocated for the pixel cache. Once this threshold is exceeded, all subsequent pixels cache operations are to/from disk.

Parameters:

  • threshold (Numeric)

    the number of megabytes to set.



323
324
325
326
327
328
329
330
# File 'ext/RMagick/rmagick.c', line 323

VALUE
Magick_set_cache_threshold(VALUE class, VALUE threshold)
{
    unsigned long thrshld = NUM2ULONG(threshold);
    SetMagickResourceLimit(MemoryResource, (MagickSizeType)thrshld);
    SetMagickResourceLimit(MapResource, (MagickSizeType)(2*thrshld));
    return class;
}

.set_log_event_mask(*args) ⇒ Object

Set the log event mask.

The arguments are one of:

  • “all”

  • “annotate”

  • “blob”

  • “cache”

  • “coder”

  • “configure”

  • “deprecate”

  • “locale”

  • “none”

  • “render”

  • “transform”

  • “user”

  • “x11”

Multiple events can be specified as the aruments. Event names may be capitalized.

Parameters:

  • args (String)

    the mask of log event.



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'ext/RMagick/rmagick.c', line 356

VALUE
Magick_set_log_event_mask(int argc, VALUE *argv, VALUE class)
{
    int x;

    if (argc == 0)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (at least 1 required)");
    }
    for (x = 0; x < argc; x++)
    {
        SetLogEventMask(StringValueCStr(argv[x]));
    }
    return class;
}

.set_log_format(format) ⇒ Object

Set the format for log messages.

Format is a string containing one or more of:

  • %t - current time

  • %r - elapsed time

  • %u - user time

  • %p - pid

  • %m - module (source file name)

  • %f - function name

  • %l - line number

  • %d - event domain (one of the events listed above)

  • %e - event name

  • Plus other characters, including \n, etc.

Parameters:

  • format (String)

    the format to set.



390
391
392
393
394
395
# File 'ext/RMagick/rmagick.c', line 390

VALUE
Magick_set_log_format(VALUE class, VALUE format)
{
    SetLogFormat(StringValueCStr(format));
    return class;
}