Class: RGD::Image

Inherits:
Object
  • Object
show all
Defined in:
ext/rgd/rgd.c

Constant Summary collapse

ALPHA_MAX =

Same as ALPHA_TRANSPARENT.

gdAlphaMax
ALPHA_OPAQUE =

Does not blend at all with the background.

gdAlphaOpaque
ALPHA_TRANSPARENT =

Allows the background to shine through 100%.

gdAlphaTransparent
MAX_COLORS =

Max colors can be used in palette-based image.

gdMaxColors
GD2_FMT_RAW =

Uncompressed GD2 format.

GD2_FMT_RAW
GD2_FMT_COMPRESSED =

Compressed GD2 format.

GD2_FMT_COMPRESSED
DISPOSAL_NONE =

Restores the first allocated color of the global palette.

gdDisposalNone
DISPOSAL_RESTORE_BACKGROUND =

Restores the appearance of the affected area before the frame was rendered.

gdDisposalRestoreBackground
DISPOSAL_RESTORE_PREVIOUS =

The pixels changed by this frame should remain on the display when the next frame begins to render.

gdDisposalRestorePrevious
GD_CMP_IMAGE =

Actual image IS different

GD_CMP_IMAGE
GD_CMP_NUM_COLORS =

Number of Colors in pallette differ

GD_CMP_NUM_COLORS
GD_CMP_COLOR =

Image Colors differ

GD_CMP_COLOR
GD_CMP_SIZE_X =

Image width differs

GD_CMP_SIZE_X
GD_CMP_SIZE_Y =

Image heights differ

GD_CMP_SIZE_Y
GD_CMP_TRANSPARENT =

Transparent color

GD_CMP_TRANSPARENT
GD_CMP_BACKGROUND =

Background color

GD_CMP_BACKGROUND
GD_CMP_INTERLACE =

Interlaced setting

GD_CMP_INTERLACE
GD_CMP_TRUECOLOR =

Truecolor vs palette differs

GD_CMP_TRUECOLOR
COLOR_STYLED =

Special color.

gdStyled
COLOR_BRUSHED =

Special color.

gdBrushed
COLOR_STYLED_BRUSHED =

Special color.

gdStyledBrushed
COLOR_TILED =

Special color.

gdTiled
COLOR_TRANSPARENT =

Special color. NOT the same as the transparent color index. This is used in line styles only.

gdTransparent
COLOR_ANTIALIASED =

Special color.

gdAntiAliased
STYLE_ARC =

See Image.filled_arc.

gdArc
STYLE_CHORD =

See Image.filled_arc.

gdChord
STYLE_PIE =

See Image.filled_arc.

gdPie
STYLE_NO_FILL =

See Image.filled_arc.

gdNoFill
STYLE_EDGED =

See Image.filled_arc.

gdEdged
CHARMAP_UNICODE =

See Image.stringft.

gdFTEX_Unicode
CHARMAP_SHIFT_JIS =

See Image.stringft.

gdFTEX_Shift_JIS
CHARMAP_BIG5 =

See Image.stringft.

gdFTEX_Big5
CHARMAP_ADOBE_CUSTOM =

See Image.stringft.

gdFTEX_Adobe_Custom

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.alpha_blend(dst, src) ⇒ Object

Accepts truecolor pixel values only. The source color is composited with the destination color based on the alpha channel value of the source color.

The resulting color is opaque.



358
359
360
# File 'ext/rgd/rgd.c', line 358

static VALUE image_s_alpha_blend(VALUE klass, VALUE dst, VALUE src) {
    return INT2NUM(gdAlphaBlend(NUM2INT(dst), NUM2INT(src)));
}

.create(width, height) ⇒ Object

Creates a palette-based image, with no more than 256 colors.



405
406
407
# File 'ext/rgd/rgd.c', line 405

static VALUE image_s_create(VALUE klass, VALUE width, VALUE height) {
    return gd_image_create(klass, width, height, gdImageCreate);
}

.create_palette_from_truecolor(img, dither = true, colors = MAX_COLORS) ⇒ Object

Create a new palette-based image from a truecolor image, by using a high-quality two-pass quantization routine. If dither is true, the image will be dithered to approximate colors better, at the expense of some obvious “speckling.” colors can be anything up to 256. If the original source image includes photographic information or anything that came out of a JPEG, 256 is strongly recommended. 100% transparency of a single transparent color in the original truecolor image will be preserved. There is no other support for preservation of alpha channel or transparency in the destination image.



690
691
692
693
694
695
696
697
698
699
# File 'ext/rgd/rgd.c', line 690

static VALUE image_s_create_palette_from_truecolor(int argc, VALUE *argv, VALUE klass) {
    gdImagePtr im, im2;
    VALUE img2, dither, colors;
    rb_scan_args(argc, argv, "12", &img2, &dither, &colors);
    SetIntIfQnil(dither, Qtrue);
    Data_Get_Struct(img2, gdImage, im2);
    im = gdImageCreatePaletteFromTrueColor(im2, RTEST(dither) ? 1 : 0, RTEST(colors) ? NUM2INT(colors) : gdMaxColors);
    if (!im) rb_raise(rb_eRGDError, "Not valid Image data");
    return Data_Wrap_Struct(klass, 0, gd_image_free, im);
}

.create_truecolor(width, height) ⇒ Object

Creates a truecolor image, with an essentially unlimited number of colors.



415
416
417
# File 'ext/rgd/rgd.c', line 415

static VALUE image_s_create_truecolor(VALUE klass, VALUE width, VALUE height) {
    return gd_image_create(klass, width, height, gdImageCreateTrueColor);
}

.from_bmp(filename) ⇒ Object

Creates a image from a BMP format file.



647
648
649
# File 'ext/rgd/rgd.c', line 647

static VALUE image_s_from_bmp(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromBmp);
}

.from_bmp_data(data) ⇒ Object

Creates a image from a BMP format byte-string.



506
507
508
# File 'ext/rgd/rgd.c', line 506

static VALUE image_s_from_bmp_data(VALUE klass, VALUE data) {
    return gd_image_create_from_data(klass, data, gdImageCreateFromBmpPtr);
}

.from_data(data, format = nil) ⇒ Object

Create a new image from a byte-string.

The argument format should be a image format name, like “jpeg”, “png”, etc. If it’s nil, the image type will be detected automatically by the MAGIC of data (work for JPEG, PNG, GIF, BMP, GD2 and GD).



2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
# File 'ext/rgd/rgd.c', line 2586

static VALUE image_s_from_data(int argc, VALUE* argv, VALUE klass) {
    VALUE data, format;
    char *ext;
    ImageFormat i_fmt = FMT_UNKNOW;

    if (rb_scan_args(argc, argv, "11", &data, &format) == 2) Check_Type(format, T_STRING);
    Check_Type(data, T_STRING);

    if (RTEST(format)) {
        i_fmt = m_image_detect_format_by_ext(RSTRING_PTR(format));
    } else {
    	i_fmt = m_image_detect_format_by_magic(RSTRING_PTR(data));
    }

    switch (i_fmt) {
        case FMT_JPEG:
            return image_s_from_jpeg_data(klass, data);
        case FMT_PNG:
            return image_s_from_png_data(klass, data);
        case FMT_GIF:
            return image_s_from_gif_data(klass, data);
        case FMT_BMP:
            return image_s_from_bmp_data(klass, data);
        case FMT_GD2:
            return image_s_from_gd2_data(klass, data);
        case FMT_GD:
            return image_s_from_gd_data(klass, data);
        case FMT_WBMP:
            return image_s_from_wbmp_data(klass, data);
        case FMT_XBM:
            rb_raise(rb_eRGDError, "Cannot load a XBM image from a byte-string.");
        case FMT_XPM:
            rb_raise(rb_eRGDError, "Cannot load a XPM image from a byte-string.");
        default:
            if (RTEST(format)) {
                rb_raise(rb_eRGDError, "Unknown image format: %s", RSTRING_PTR(format));
            } else {
                rb_raise(rb_eRGDError, "Cannot detect image format");
            }
    }
}

.from_gd(filename) ⇒ Object

Creates a image from a GD format file.



606
607
608
# File 'ext/rgd/rgd.c', line 606

static VALUE image_s_from_gd(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromGd);
}

.from_gd2(filename) ⇒ Object

Creates a image from a GD2 format file, with extra parameters indicating the source (x, y) and width/height of the desired image.



617
618
619
# File 'ext/rgd/rgd.c', line 617

static VALUE image_s_from_gd2(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromGd2);
}

.from_gd2_data(data) ⇒ Object

Creates a image from a GD2 format byte-string.



486
487
488
# File 'ext/rgd/rgd.c', line 486

static VALUE image_s_from_gd2_data(VALUE klass, VALUE data) {
    return gd_image_create_from_data(klass, data, gdImageCreateFromGd2Ptr);
}

.from_gd2_part(filename, x, y, width, height) ⇒ Object

Create a image from a GD2 format file, with extra parameters indicating the source (x, y) and width/height of the desired image.



659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'ext/rgd/rgd.c', line 659

static VALUE image_s_from_gd2_part(VALUE klass, VALUE filename, VALUE x, VALUE y, VALUE w, VALUE h) {
    gdImagePtr im;
    FILE* fp;

    Check_Type(x, T_FIXNUM);Check_Type(y, T_FIXNUM);
    Check_Type(w, T_FIXNUM);Check_Type(h, T_FIXNUM);
    fp = fopen(RSTRING_PTR(filename), "rb");
    if (!fp) rb_raise(rb_eIOError, "Cannot open %s for read", RSTRING_PTR(filename));

    im = gdImageCreateFromGd2Part(fp, NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
    fclose(fp);

    if (!im) rb_raise(rb_eRGDError, "Not valid Image: %s", RSTRING_PTR(filename));
    return Data_Wrap_Struct(klass, 0, gd_image_free, im);
}

.from_gd2_part_data(data, x, y, width, height) ⇒ Object

Create a image from a GD2 format byte-string, with extra parameters indicating the source (x, y) and width/height of the desired image.



518
519
520
521
522
523
524
525
526
527
# File 'ext/rgd/rgd.c', line 518

static VALUE image_s_from_gd2_part_data(VALUE klass, VALUE data, VALUE x, VALUE y, VALUE w, VALUE h) {
    gdImagePtr im;

    Check_Type(data, T_STRING);
    Check_Type(x, T_FIXNUM);Check_Type(y, T_FIXNUM);
    Check_Type(w, T_FIXNUM);Check_Type(h, T_FIXNUM);
    im = gdImageCreateFromGd2PartPtr(RSTRING_LEN(data), RSTRING_PTR(data), NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h));
    if (!im) rb_raise(rb_eRGDError, "Not valid Image data");
    return Data_Wrap_Struct(klass, 0, gd_image_free, im);
}

.from_gd_data(data) ⇒ Object

Creates a image from a GD format byte-string.



476
477
478
# File 'ext/rgd/rgd.c', line 476

static VALUE image_s_from_gd_data(VALUE klass, VALUE data) {
    return gd_image_create_from_data(klass, data, gdImageCreateFromGdPtr);
}

.from_gif(filename) ⇒ Object

Creates a image from a GIF format file.



596
597
598
# File 'ext/rgd/rgd.c', line 596

static VALUE image_s_from_gif(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromGif);
}

.from_gif_data(data) ⇒ Object

Creates a image from a GIF format byte-string.



466
467
468
# File 'ext/rgd/rgd.c', line 466

static VALUE image_s_from_gif_data(VALUE klass, VALUE data) {
    return gd_image_create_from_data(klass, data, gdImageCreateFromGifPtr);
}

.from_jpeg(filename) ⇒ Object

Creates a truecolor image from a JPEG format file.



566
567
568
# File 'ext/rgd/rgd.c', line 566

static VALUE image_s_from_jpeg(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromJpeg);
}

.from_jpeg_data(data) ⇒ Object

Creates a truecolor image from a JPEG format byte-string.



436
437
438
# File 'ext/rgd/rgd.c', line 436

static VALUE image_s_from_jpeg_data(VALUE klass, VALUE data) {
    return gd_image_create_from_data(klass, data, gdImageCreateFromJpegPtr);
}

.from_png(filename) ⇒ Object

Creates a image from a PNG format file.

If the PNG image being loaded is a truecolor image, the result will be a truecolor image. If the PNG image being loaded is a palette or grayscale image, the result will be a palette image. gd retains only 8 bits of resolution for each of the red, green and blue channels, and only 7 bits of resolution for the alpha channel. The former restriction affects only a handful of very rare 48-bit color and 16-bit grayscale PNG images. The second restriction affects all semitransparent PNG images, but the difference is essentially invisible to the eye. 7 bits of alpha channel resolution is, in practice, quite a lot.



586
587
588
# File 'ext/rgd/rgd.c', line 586

static VALUE image_s_from_png(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromPng);
}

.from_png_data(data) ⇒ Object

Creates a image from a PNG format byte-string.

If the PNG image being loaded is a truecolor image, the result will be a truecolor image. If the PNG image being loaded is a palette or grayscale image, the result will be a palette image. gd retains only 8 bits of resolution for each of the red, green and blue channels, and only 7 bits of resolution for the alpha channel. The former restriction affects only a handful of very rare 48-bit color and 16-bit grayscale PNG images. The second restriction affects all semitransparent PNG images, but the difference is essentially invisible to the eye. 7 bits of alpha channel resolution is, in practice, quite a lot.



456
457
458
# File 'ext/rgd/rgd.c', line 456

static VALUE image_s_from_png_data(VALUE klass, VALUE data) {
    return gd_image_create_from_data(klass, data, gdImageCreateFromPngPtr);
}

.from_wbmp(filename) ⇒ Object

Creates a image from a WBMP format file.



627
628
629
# File 'ext/rgd/rgd.c', line 627

static VALUE image_s_from_wbmp(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromWBMP);
}

.from_wbmp_data(data) ⇒ Object

Creates a image from a WBMP format byte-string.



496
497
498
# File 'ext/rgd/rgd.c', line 496

static VALUE image_s_from_wbmp_data(VALUE klass, VALUE data) {
    return gd_image_create_from_data(klass, data, gdImageCreateFromWBMPPtr);
}

.from_xbm(filename) ⇒ Object

Creates a image from a XBM format file.



637
638
639
# File 'ext/rgd/rgd.c', line 637

static VALUE image_s_from_xbm(VALUE klass, VALUE filename) {
    return gd_image_create_from_file(klass, filename, gdImageCreateFromXbm);
}

.from_xpm(filename) ⇒ Object

Creates a image from a XPM file.



536
537
538
539
540
541
542
543
544
# File 'ext/rgd/rgd.c', line 536

static VALUE image_s_from_xpm(VALUE klass, VALUE filename) {
    gdImagePtr im;

    if (rb_funcall(rb_cFile, rb_intern("readable?"), 1, filename) != Qtrue)
        rb_raise(rb_eIOError, "Cannot open %s for read", RSTRING_PTR(filename));
    im = gdImageCreateFromXpm(RSTRING_PTR(filename));
    if (!im) rb_raise(rb_eRGDError, "Not valid Image: %s", RSTRING_PTR(filename));
    return Data_Wrap_Struct(klass, 0, gd_image_free, im);
}

.new(filename, format = nil) ⇒ Object

Create a new image from a file.

The argument format should be a image format name, like “jpeg”, “png”, etc. If it’s nil, the image type will be detected automatically by the extension of filename.



2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
# File 'ext/rgd/rgd.c', line 2532

static VALUE image_s_new(int argc, VALUE* argv, VALUE klass) {
    VALUE filename, format;
    char *ext;
    ImageFormat i_fmt = FMT_UNKNOW;

    if (rb_scan_args(argc, argv, "11", &filename, &format) == 2) Check_Type(format, T_STRING);
    Check_Type(filename, T_STRING);
    if (rb_funcall(rb_cFile, rb_intern("readable?"), 1, filename) != Qtrue) rb_raise(rb_eArgError, "%s is not readable", RSTRING_PTR(filename));

    if (RTEST(format)) {
        i_fmt = m_image_detect_format_by_ext(RSTRING_PTR(format));
    } else {
        ext = strrchr(RSTRING_PTR(filename), '.');
        if (ext && ++ext) i_fmt = m_image_detect_format_by_ext(ext);
    }

    switch (i_fmt) {
        case FMT_JPEG:
            return image_s_from_jpeg(klass, filename);
        case FMT_PNG:
        	return image_s_from_png(klass, filename);
        case FMT_GIF:
        	return image_s_from_gif(klass, filename);
        case FMT_BMP:
        	return image_s_from_bmp(klass, filename);
        case FMT_GD2:
        	return image_s_from_gd2(klass, filename);
        case FMT_GD:
        	return image_s_from_gd(klass, filename);
        case FMT_WBMP:
        	return image_s_from_wbmp(klass, filename);
        case FMT_XBM:
            return image_s_from_xbm(klass, filename);
        case FMT_XPM:
            return image_s_from_xpm(klass, filename);
        default:
            if (RTEST(format)) {
                rb_raise(rb_eRGDError, "Unknown image format: %s", RSTRING_PTR(format));
            } else {
                rb_raise(rb_eRGDError, "Cannot detect image format: %s", RSTRING_PTR(filename));
            }
    }
}

.square_to_circle(img, radius) ⇒ Object

The argument img MUST be square, but can have any size. Returns a new image of width and height radius * 2, in which the X axis of the original has been remapped to theta (angle) and the Y axis of the original has been remapped to rho (distance from center). This is known as a “polar coordinate transform.”

See also Image.stringft_circle, which uses this function internally.



713
714
715
716
717
718
719
# File 'ext/rgd/rgd.c', line 713

static VALUE image_s_square_to_circle(VALUE klass, VALUE img2, VALUE radius) {
    gdImagePtr im, im2;
    Data_Get_Struct(img2, gdImage, im2);
    im = gdImageSquareToCircle(im2, NUM2INT(radius));
    if (!im) rb_raise(rb_eRGDError, "Not valid Image data");
    return Data_Wrap_Struct(klass, 0, gd_image_free, im);
}

.stringft(fg, fontname, ptsize, angle, x, y, str, opts = {}) ⇒ Object

Draws a string of anti-aliased characters on the image using the FreeType library to render user-supplied TrueType fonts. The string is anti-aliased, meaning that there should be fewer “jaggies” visible. The fontname is the full pathname to a TrueType font file, or a font face name if the GDFONTPATH environment variable or the compiled-in DEFAULT_FONTPATH macro of gdft.c have been set intelligently. In the absence of a full path, the font face name may be presented with or without extension (2.0.26).

The null-terminated string argument is considered to be encoded via the UTF_8 standard; also, HTML entities are supported, including decimal, hexadecimal, and named entities (2.0.26). Those who are passing ordinary ASCII strings may have difficulty with the & character unless encoded correctly as & but should have no other difficulties.

The string may be arbitrarily scaled (ptsize) and rotated (angle in radians). The direction of rotation is counter-clockwise, with 0 radians (0 degrees) at 3 o’clock and PI/2 radians (90 degrees) at 12 o’clock.

The string is rendered in the color indicated by the fg color index. Use the negative of the desired color index to disable anti-aliasing.

The string may contain UTF-8 sequences like: “À”

This method returns a hash object, and the element with key “brect” is an array filled with 4 elements representing the 4 corner coordinates of the bounding rectangle (the smallest rectangle that completely surrounds the rendered string and does not intersect any pixel of the rendered string).

[ [lower_left_X, lower_left_Y], [lower_right_X, lower_right_Y], [upper_right_X, upper_right_Y], [upper_left_X, upper_left_Y] ]

Use Image::stringft to get the bounding rectangle without rendering. This is a relatively cheap operation if followed by a rendering of the same string, because of the caching of the partial rendering during bounding rectangle calculation.

Options:

  • :linespcing => double

  • :charmap => CHARMAP_*

  • :hdpi => integer

  • :vdpi => integer

  • :kerning => boolean

  • :xshow => boolean

  • :fontpath => boolean

  • :fontconfig => boolean

To output multiline text with a specific line spacing, set the option :linespacing to the desired spacing, expressed as a multiple of the font height. Thus a line spacing of 1.0 is the minimum to guarantee that lines of text do not collide. If :linespacing is not present, linespacing defaults to 1.05.

To specify a preference for Unicode, Shift_JIS Big5 character encoding, set the option :charmap to CHARMAP_*. If you do not specify a preference, Unicode will be tried first. If the preferred character mapping is not found in the font, other character mappings are attempted.

GD operates on the assumption that the output image will be rendered to a computer screen. By default, gd passes a resolution of 96 dpi to the freetype text rendering engine. This influences the “hinting” decisions made by the renderer. To specify a different resolution, set :hdpi and :vdpi accordingly (in dots per inch).

GD 2.0.29 and later will normally attempt to apply kerning tables, if fontconfig is available, to adjust the relative positions of consecutive characters more ideally for that pair of characters. This can be turn off by set the option :kerning to false;

GD 2.0.29 and later can return a vector of individual character position advances by set the option :xshow to true, occasionally useful in applications that must know exactly where each character begins. This is returned in the element with key “xshow”.

GD 2.0.29 and later can also return the path to the actual font file used if the option :returnfontpath is true. This is useful because GD 2.0.29 and above are capable of selecting a font automatically based on a fontconfig font pattern when fontconfig is available. This information is returned in the element with key “fontpath”.

GD 2.0.29 and later can use fontconfig to resolve font names, including fontconfig patterns, if the option :fontconfig is true. As a convenience, this behavior can be made the default by calling Image.use_fontconfig=true. In that situation it is not necessary to set the option :fontconfig on every call; however explicit font path names can still be used if the option :fontpathname is true.

Unless Image.use_fontconfig=true has been called, GD 2.0.29 and later will still expect the fontlist argument to the freetype text output functions to be a font file name or list thereof as in previous versions. If you do not wish to make fontconfig the default, it is still possible to force the use of fontconfig for a single call to the freetype text output functions by setting the option :fontconfig to ture.



2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
# File 'ext/rgd/rgd.c', line 2413

static VALUE image_stringft(int argc, VALUE *argv, VALUE klass) {
    VALUE fg, fontname, ptsize, angle, x, y, str, opts;
    VALUE ret, m, n;
    gdImagePtr im = NULL;
    gdFTStringExtra ftex;
    int brect[8];
    char *err;

    if (TYPE(klass) == T_DATA) Data_Get_Struct(klass, gdImage, im);
    memset(&ftex, 0, sizeof(gdFTStringExtra));
    if (rb_scan_args(argc, argv, "71", &fg, &fontname, &ptsize, &angle, &x, &y, &str, &opts) == 7) {
        err = gdImageStringFT(im, &brect[0], NUM2INT(fg), RSTRING_PTR(fontname), NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING_PTR(str));
    } else {
        Check_Type(opts, T_HASH);

        m = rb_hash_aref(opts, STR2SYM("linespacing"));
        if (RTEST(m)) {
            ftex.flags |= gdFTEX_LINESPACE;
            ftex.linespacing = NUM2DBL(m);
        }

        m = rb_hash_aref(opts, STR2SYM("charmp"));
        if (RTEST(m)) {
            ftex.flags |= gdFTEX_CHARMAP;
            ftex.charmap = NUM2INT(m);
        }

        m = rb_hash_aref(opts, STR2SYM("hdpi"));
        n = rb_hash_aref(opts, STR2SYM("vdpi"));
        if (RTEST(m) && RTEST(n)) {
            ftex.flags |= gdFTEX_RESOLUTION;
            ftex.hdpi = NUM2INT(m);
            ftex.vdpi = NUM2INT(n);
        }

        m = rb_hash_aref(opts, STR2SYM("kerning"));
        if (m == Qfalse) ftex.flags |= gdFTEX_DISABLE_KERNING;

        m = rb_hash_aref(opts, STR2SYM("xshow"));
        if (RTEST(m)) ftex.flags |= gdFTEX_XSHOW;

        m = rb_hash_aref(opts, STR2SYM("returnfontpath"));
        if (RTEST(m)) ftex.flags |= gdFTEX_RETURNFONTPATHNAME;

        m = rb_hash_aref(opts, STR2SYM("fontpathname"));
        if (RTEST(m)) ftex.flags |= gdFTEX_FONTPATHNAME;

        m = rb_hash_aref(opts, STR2SYM("fontconfig"));
        if (RTEST(m)) ftex.flags |= gdFTEX_FONTCONFIG;

        err = gdImageStringFTEx(im, &brect[0], NUM2INT(fg), RSTRING_PTR(fontname), NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING_PTR(str), &ftex);
    }

    if (err) rb_raise(rb_eRGDError, "%s", err);

    ret = rb_hash_new();
    rb_hash_aset(ret, rb_str_new2("brect"),
        rb_ary_new3(4,
            rb_ary_new3(2, INT2NUM(brect[0]), INT2NUM(brect[1])),
            rb_ary_new3(2, INT2NUM(brect[2]), INT2NUM(brect[3])),
            rb_ary_new3(2, INT2NUM(brect[4]), INT2NUM(brect[5])),
            rb_ary_new3(2, INT2NUM(brect[6]), INT2NUM(brect[7]))
        ));

    if (ftex.flags != 0) {
        if (ftex.xshow) {
            rb_hash_aset(ret, rb_str_new2("xshow"), rb_str_new2(ftex.xshow));
            gdFree(ftex.xshow);
        }

        if (ftex.fontpath) {
            rb_hash_aset(ret, rb_str_new2("fontpath"), rb_str_new2(ftex.fontpath));
            gdFree(ftex.fontpath);
        }
    }

    return ret;
}

.truecolor(args) ⇒ Object

Returns an RGBA color value for use when drawing on a truecolor image.

Usage:

  • truecolor(color_name)

  • truecolor(r, g, b, a = ALPHA_OPAQUE)

color_name can be any one of 147 color names are defined in the HTML and CSS color specification.

Red, green, and blue are all in the range between 0 (off) and 255 (maximum). Alpha is in the range between ALPHA_OPAQUE (opaque) and ALPHA_TRANSPARENT (fully transparent). This method should not be used with palette-based images. If you need to write code which is compatible with both palette-based and truecolor images, use Image.color_resolve.



383
384
385
386
# File 'ext/rgd/rgd.c', line 383

static VALUE image_s_truecolor(int argc, VALUE *argv, VALUE klass) {
    VALUE r = m_scan_color_args(argc, argv);
    return INT2NUM(gdTrueColorAlpha(NUM2INT(rb_ary_entry(r, 0)), NUM2INT(rb_ary_entry(r, 1)), NUM2INT(rb_ary_entry(r, 2)), NUM2INT(rb_ary_entry(r, 3))));
}

.use_fontconfig=(boolean) ⇒ Object

GD 2.0.29 introduced the ability to use fontconfig patterns rather than font file names as parameters to Image.stringft, Image.stringft_circle. For backwards compatibility reasons, the fontlist parameter to those functions is still expected to be a full or partial font file path name or list thereof by default. However, as a convenience, when use_fontconfig=true configures gd to expect the fontlist parameter to be a fontconfig pattern.

NOTE, if the fontconfig library is not available, use_fontconfig=true will raise an error.



342
343
344
345
346
# File 'ext/rgd/rgd.c', line 342

static VALUE image_s_use_fontconfig(VALUE klass, VALUE flag) {
    if (!gdFTUseFontConfig(RTEST(flag) ? 1 : 0)) {
        rb_raise(rb_eRGDError, "The FontConfig library is not available.");
    }
}

Instance Method Details

#[](x, y) ⇒ Object

Get the color index or the color values of a particular pixel.

A color index is returned when the image is palette based (created by Image.create), the color value is returned when the image is a true color image (created by Image.create_truecolor). To fetch the value of each channel, you can use Image.rgba.



1241
1242
1243
# File 'ext/rgd/rgd.c', line 1241

static VALUE image_get_pixel(VALUE klass, VALUE x, VALUE y) {
    return gd_H__gip_H2(klass, x, y, gdImageGetPixel);
}

#[]=(x, y) ⇒ Object

Sets a pixel to a particular color index.



1892
1893
1894
# File 'ext/rgd/rgd.c', line 1892

static VALUE image_set_pixel(VALUE klass, VALUE x, VALUE y, VALUE color) {
    return gd_X__gip_H3(klass, x, y, color, gdImageSetPixel);
}

#aa_blendObject

TODO: document for aa_blend.



2223
2224
2225
2226
2227
2228
# File 'ext/rgd/rgd.c', line 2223

static VALUE image_aa_blend(VALUE klass) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    gdImageAABlend(im);
    return klass;
}

#alpha_blending=(boolean) ⇒ Object

This method allows for two different modes of drawing on truecolor images. In blending mode, which is on by default (gd 2.0.2 and above), the alpha channel component of the color supplied to all drawing functions, such as Image.pixels[]=, determines how much of the underlying color should be allowed to shine through. As a result, gd automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. Blending mode is not available when drawing on palette images.



1757
1758
1759
# File 'ext/rgd/rgd.c', line 1757

static VALUE image_set_alpha_blending(VALUE klass, VALUE blending) {
    return gd_X__gip_H(klass, RTEST(blending) ? INT2NUM(1) : INT2NUM(0) , gdImageAlphaBlending);
}

#antialiased=(color) ⇒ Object

“Antialiasing” is a process by which jagged edges associated with line drawing can be reduced by blending the foreground color with an appropriate percentage of the background, depending on how much of the pixel in question is actually within the boundaries of the line being drawn. All line-drawing functions, such as Image.line, Image.open_polygon and Image.polygon, will draw antialiased lines if the special “color” COLOR_ANTIALIASED is used when calling them.

this method is used to specify the actual foreground color to be used when drawing antialiased lines. You may set any color to be the foreground, however as of version 2.0.12 an alpha channel component is not supported.

Antialiased lines can be drawn on both truecolor and palette-based images. However, attempts to draw antialiased lines on highly complex palette-based backgrounds may not give satisfactory results, due to the limited number of colors available in the palette. Antialiased line-drawing on simple backgrounds should work well with palette-based images; otherwise create or fetch a truecolor image instead.



1727
1728
1729
# File 'ext/rgd/rgd.c', line 1727

static VALUE image_set_antialiased(VALUE klass, VALUE color){
    return gd_X__gip_H(klass, color, gdImageSetAntiAliased);
}

#antialiased_dont_blend(color, boolean) ⇒ Object

Normally, when drawing lines with the special COLOR_ANTIALIASED “color,” blending with the background to reduce jagged edges is the desired behavior. However, when it is desired that lines not be blended with one particular color when it is encountered in the background, this method can be used to indicate the special color that the foreground should stand out more clearly against.



1875
1876
1877
# File 'ext/rgd/rgd.c', line 1875

static VALUE image_set_antialiased_dont_blend(VALUE klass, VALUE color, VALUE dont_blend) {
    return gd_X__gip_H2(klass, color, RTEST(dont_blend) ? INT2NUM(1) : INT2NUM(0), gdImageSetAntiAliasedDontBlend);
}

#arc(cx, cy, w, h, s, e, color) ⇒ Object

Used to draw a partial ellipse centered at the given point, with the specified width and height in pixels. The arc begins at the position in degrees specified by s and ends at the position specified by e. The arc is drawn in the color specified by the last argument. A circle can be drawn by beginning from 0 degrees and ending at 360 degrees, with width and height being equal. e must be greater than s. Values greater than 360 are interpreted modulo 360.



2053
2054
2055
2056
2057
# File 'ext/rgd/rgd.c', line 2053

static VALUE image_arc(VALUE klass, VALUE cx, VALUE cy, VALUE w, VALUE h, VALUE s, VALUE e, VALUE color) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    gdImageArc(im, NUM2INT(cx), NUM2INT(cy), NUM2INT(w), NUM2INT(h), NUM2INT(s), NUM2INT(e), NUM2INT(color));
}

#bmp(filename) ⇒ Object

Write the image to the specified file in BMP format.



817
818
819
# File 'ext/rgd/rgd.c', line 817

static VALUE image_bmp(VALUE klass, VALUE filename) {
    return gd_image_to_file_H(klass, filename, 1, gdImageBmp);
}

#bmp_dataObject

Convert the image to a BMP format byte-string.



979
980
981
# File 'ext/rgd/rgd.c', line 979

static VALUE image_bmp_data(VALUE klass) {
    return gd_image_to_data_H(klass, INT2NUM(1), gdImageBmpPtr);
}

#bounds_safe(x, y) ⇒ Boolean

Returns true if the specified point is within the current clipping rectangle, false if not. The clipping rectangle is set by Image.clip= and defaults to the entire image. This function is intended primarily for use by those who wish to add functions to gd.

Returns:

  • (Boolean)


1254
1255
1256
# File 'ext/rgd/rgd.c', line 1254

static VALUE image_bounds_safe(VALUE klass, VALUE x, VALUE y) {
    return gd_H__gip_H2(klass, x, y, gdImageBoundsSafe) == INT2NUM(0) ? Qfalse : Qtrue;
}

#brush=(img) ⇒ Object

A “brush” is an image used to draw wide, shaped strokes in another image. Just as a paintbrush is not a single point, a brush image need not be a single pixel. Any gd image can be used as a brush, and by setting the transparent color index of the brush image with Image.transparent=, a brush of any shape can be created. All line-drawing functions, such as Image.line, Image.open_polygon and Image.polygon, will use the current brush if the special “color” COLOR_BRUSHED or COLOR_STYLED_BRUSHED is used when calling them.

This method is used to specify the brush to be used in a particular image. You can set any image to be the brush. If the brush image does not have the same color map as the first image, any colors missing from the first image will be allocated. If not enough colors can be allocated, the closest colors already available will be used. This allows arbitrary PNGs to be used as brush images. It also means, however, that you should not set a brush unless you will actually use it; if you set a rapid succession of different brush images, you can quickly fill your color map, and the results will not be optimal.



1439
1440
1441
# File 'ext/rgd/rgd.c', line 1439

static VALUE image_set_brush(VALUE klass, VALUE img2) {
    return gd_X__gip2(klass, img2, gdImageSetBrush);
}

#char(font, x, y, c, color) ⇒ Object

Used to draw single characters on the image. (To draw multiple characters, use Image.string. See also Image.stringft for a high quality solution.)

The character specified by the fifth argument c is drawn from left to right in the specified color. (See Image.char_up for a way of drawing vertical text.) Pixels not set by a particular character retain their previous color.



2293
2294
2295
# File 'ext/rgd/rgd.c', line 2293

static VALUE image_char(VALUE klass, VALUE font, VALUE x, VALUE y, VALUE c, VALUE color) {
    return gd_image_char(klass, font, x, y, c, color, gdImageChar);
}

#char_up(font, x, y, c, color) ⇒ Object

Used to draw single characters on the image, rotated 90 degrees. (To draw multiple characters, use Image.string_up.)

The character specified by the fifth argument c is drawn from bottom to top, rotated at a 90-degree angle, in the specified color. (See Image.char for a way of drawing horizontal text.) Pixels not set by a particular character retain their previous color.



2309
2310
2311
# File 'ext/rgd/rgd.c', line 2309

static VALUE image_char_up(VALUE klass, VALUE font, VALUE x, VALUE y, VALUE c, VALUE color) {
    return gd_image_char(klass, font, x, y, c, color, gdImageCharUp);
}

#x1Object

Fetches the boundaries of the current clipping rectangle.



2101
2102
2103
2104
2105
2106
2107
# File 'ext/rgd/rgd.c', line 2101

static VALUE image_get_clip(VALUE klass) {
    int x1, y1, x2, y2;
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    gdImageGetClip(im, &x1, &y1, &x2, &y2);
    return rb_ary_new3(4, INT2NUM(x1), INT2NUM(y1), INT2NUM(x2), INT2NUM(y2));
}

#clip=(x1) ⇒ Object

Establishes a clipping rectangle. Once this method has been called, all future drawing operations will remain within the specified clipping area, until a new call takes place. For instance, if a clipping rectangle of 25, 25, 75, 75 has been set within a 100x100 image, a diagonal line from 0,0 to 99,99 will appear only between 25,25 and 75,75.

If this method is never called, the clipping area will be the entire image.

The parameters passed in are checked against the dimensions of the image and limited to “safe” values.



1966
1967
1968
# File 'ext/rgd/rgd.c', line 1966

static VALUE image_set_clip(VALUE klass, VALUE x1, VALUE y1, VALUE x2, VALUE y2) {
    return gd_X__gip_H4(klass, x1, y1, x2, y2, gdImageSetClip);
}

#cloneObject

Return a new image clone from current.



2758
2759
2760
2761
2762
2763
2764
2765
# File 'ext/rgd/rgd.c', line 2758

static VALUE image_clone(VALUE klass) {
    VALUE nimage, data;

    data = image_gd2_data(klass, 0, GD2_FMT_RAW);
    nimage = rb_funcall(rb_cImage, rb_intern("from_gd2_data"), 1, data);

    return nimage;
}

#color_allocate(args) ⇒ Object

Usage:

  • color_allocate(r, g, b, a = ALPHA_OPAQUE)

  • color_allocate(integer)

  • color_allocate(color_name)

Red, green and blue can be anything upto 255, and 127 represents full transparency for alpha.

color_name can be any one of 147 color names are defined in the HTML and CSS color specification.

This method finds the first available color index in the image specified, sets its RGBA values to those requested, and returns the index of the new color table entry, or an RGBA value in the case of a truecolor image; in either case you can then use the returned value as a parameter to drawing functions. When creating a new palette-based image, the first time you invoke this function, you are setting the background color for that image.

In the event that all MAX_COLORS colors (256) have already been allocated, this method will return -1 to indicate failure. (This is not uncommon when working with existing palette-based PNG files that already use 256 colors.) Note that this method does not check for existing colors that match your request; see Image.color_exact and Image.color_closest for ways to locate existing colors that approximate the color desired in situations where a new color is not available.Also see Image.color_resolve.



1333
1334
1335
# File 'ext/rgd/rgd.c', line 1333

static VALUE image_color_allocate(int argc, VALUE *argv, VALUE klass) {
    return gd_image_color_func_alpha(argc, argv, klass, gdImageColorAllocateAlpha);
}

#color_closest(args) ⇒ Object

Read Image.color_allocate for more about args.

Searches the colors which have been defined thus far in the image specified and returns the index of the color with RGB values closest to those of the request. (Closeness is determined by Euclidian distance, which is used to determine the distance in three-dimensional color space between colors.)

If no colors have yet been allocated in the image, this method returns -1. When applied to a truecolor image, this function always succeeds in returning the desired color.

This function is most useful as a backup method for choosing a drawing color when an image already contains MAX_COLORS (256) colors and no more can be allocated. (This is not uncommon when working with existing PNG files that already use many colors.) See Image.color_exact for a method of locating exact matches only.



1359
1360
1361
# File 'ext/rgd/rgd.c', line 1359

static VALUE image_color_closest(int argc, VALUE *argv, VALUE klass) {
    return gd_image_color_func_alpha(argc, argv, klass, gdImageColorClosestAlpha);
}

#color_closest_hwb(args) ⇒ Object

Usage:

  • color_closest_hwb(r, g, b)

  • color_closest_hwb(integer)

  • color_closest_hwb(color_name)

Read Image.color_allocate for more about usage.

Searches the colors which have been defined thus far in the image specified and returns the index of the color with hue, whiteness and blackness closest to the requested color. This scheme is typically superior to the Euclidian distance scheme used by Image.color_closest.

If no colors have yet been allocated in the image, this method returns -1. When applied to a truecolor image, this function always succeeds in returning the desired color.

This function is most useful as a backup method for choosing a drawing color when an image already contains MAX_COLORS (256) colors and no more can be allocated. (This is not uncommon when working with existing PNG files that already use many colors.) See Image.color_exact for a method of locating exact matches only.



1286
1287
1288
1289
1290
1291
# File 'ext/rgd/rgd.c', line 1286

static VALUE image_color_closest_hwb(int argc, VALUE *argv, VALUE klass) {
    gdImagePtr im;
    VALUE r = m_scan_color_args(argc, argv);
    Data_Get_Struct(klass, gdImage, im);
    return INT2NUM(gdImageColorClosestHWB(im, NUM2INT(rb_ary_entry(r, 0)), NUM2INT(rb_ary_entry(r, 1)), NUM2INT(rb_ary_entry(r, 2))));
}

#color_deallocate(color) ⇒ Object

Marks the specified color as being available for reuse. It does not attempt to determine whether the color index is still in use in the image. After a call to this function, the next call to Image.color_allocate for the same image will set new RGB values for that color index, changing the color of any pixels which have that index as a result. If multiple calls to this method are made consecutively, the lowest-numbered index among them will be reused by the next Image.color_allocate call.



1814
1815
1816
# File 'ext/rgd/rgd.c', line 1814

static VALUE image_color_deallocate(VALUE klass, VALUE color) {
    return gd_X__gip_H(klass, color, gdImageColorDeallocate);
}

#color_exact(args) ⇒ Object

Read Image.color_allocate for more about args.

Searches the colors which have been defined thus far in the image specified and returns the index of the color with RGBA values closest to those of the request. (Closeness is determined by Euclidian distance, which is used to determine the distance in four-dimensional color/alpha space between colors.)

If no colors have yet been allocated in the image, this method returns -1. When applied to a truecolor image, this function always succeeds in returning the desired color.

This function is most useful as a backup method for choosing a drawing color when a palette-based image already contains MAX_COLORS (256) colors and no more can be allocated. (This is not uncommon when working with existing palette-based PNG files that already use many colors.)



1383
1384
1385
# File 'ext/rgd/rgd.c', line 1383

static VALUE image_color_exact(int argc, VALUE *argv, VALUE klass) {
    return gd_image_color_func_alpha(argc, argv, klass, gdImageColorExactAlpha);
}

#color_resolve(args) ⇒ Object

Read Image.color_allocate for more about args.

Searches the colors which have been defined thus far in the image specified and returns the index of the first color with RGBA values which exactly match those of the request. If no allocated color matches the request precisely, then thid medhos tries to allocate the exact color. If there is no space left in the color table then this method returns the closest color (as in Image.color_closest). This function always returns an index of a color.

When applied to a truecolor image, this function always succeeds in returning the desired color.



1404
1405
1406
# File 'ext/rgd/rgd.c', line 1404

static VALUE image_color_resolve(int argc, VALUE *argv, VALUE klass) {
    return gd_image_color_func_alpha(argc, argv, klass, gdImageColorResolveAlpha);
}

#colors_totalObject

Returns the number of colors currently allocated in a palette image.



1176
1177
1178
1179
1180
# File 'ext/rgd/rgd.c', line 1176

static VALUE image_colors_total(VALUE klass) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    return INT2NUM(gdImageColorsTotal(im));
}

#compare(image) ⇒ Object

Returns a bitmap indicating if the two images are different. The members of the bitmap are defined as GD_CMP_*, but the most important is GD_CMP_IMAGE, which indicated that the images will actually appear different when displayed. Other, less important, differences relate to pallette entries. Any difference in the transparent color is assumed to make images display differently, even if the transparent color is not used.



1127
1128
1129
1130
1131
1132
# File 'ext/rgd/rgd.c', line 1127

static VALUE image_compare(VALUE klass, VALUE image) {
    gdImagePtr im, im2;
    Data_Get_Struct(klass, gdImage, im);
    Data_Get_Struct(image, gdImage, im2);
    return INT2NUM(gdImageCompare(im, im2));
}

#copy(src, dstX, dstY, srcX, srcY, w, h) ⇒ Object

Used to copy a rectangular portion of one image to another image. (For a way of stretching or shrinking the image in the process, see Image.copy_resized.)

The dst argument is the destination image to which the region will be copied. The src argument is the source image from which the region is copied. The dstX and dstY arguments specify the point in the destination image to which the region will be copied. The srcX and srcY arguments specify the upper left corner of the region in the source image. The w and h arguments specify the width and height of the region.

When you copy a region from one location in an image to another location in the same image, this method will perform as expected unless the regions overlap, in which case the result is unpredictable.

Important note on copying between images: since different images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. This method will attempt to find an identical RGB value in the destination image for each pixel in the copied portion of the source image by invoking Image.color_exact. If such a value is not found, this method will attempt to allocate colors as needed using Image.color_allocate. If both of these methods fail, this method will invoke Image.color_closest to find the color in the destination image which most closely approximates the color of the pixel being copied.



1508
1509
1510
1511
1512
1513
1514
# File 'ext/rgd/rgd.c', line 1508

static VALUE image_copy(VALUE klass, VALUE srcImg, VALUE dstX, VALUE dstY, VALUE srcX, VALUE srcY, VALUE w, VALUE h) {
    gdImagePtr dst, src;
    Data_Get_Struct(klass, gdImage, dst);
    Data_Get_Struct(srcImg, gdImage, src);
    gdImageCopy(dst, src, NUM2INT(dstX), NUM2INT(dstY), NUM2INT(srcX), NUM2INT(srcY), NUM2INT(w), NUM2INT(h));
    return klass;
}

#copy_merge(src, dstX, dstY, srcX, srcY, w, h, pct) ⇒ Object

This method is almost identical to GD::Image.copy, except that it ‘merges’ the two images by an amount specified in the last parameter. If the last parameter is 100, then it will function identically to GD::Image.copy - the source image replaces the pixels in the destination.

If, however, the pct parameter is less than 100, then the two images are merged. With pct = 0, no action is taken.

This feature is most useful to ‘highlight’ sections of an image by merging a solid color with pct = 50:

dst.copy_merge(src, 100, 200, 0, 0, 30, 50, 50)


1541
1542
1543
# File 'ext/rgd/rgd.c', line 1541

static VALUE image_copy_merge(VALUE klass, VALUE srcImg, VALUE dstX, VALUE dstY, VALUE srcX, VALUE srcY, VALUE w, VALUE h, VALUE pct) {
    return gd_X__gip2_H7(klass, srcImg, dstX, dstY, srcX, srcY, w, h, pct, gdImageCopyMerge);
}

#copy_merge_gray(src, dstX, dstY, srcX, srcY, w, h, pct) ⇒ Object

This method is almost identical to GD::Image.copy_merge, except that when merging images it preserves the hue of the source by converting the destination pixels to grey scale before the copy operation.



1553
1554
1555
# File 'ext/rgd/rgd.c', line 1553

static VALUE image_copy_merge_gray(VALUE klass, VALUE srcImg, VALUE dstX, VALUE dstY, VALUE srcX, VALUE srcY, VALUE w, VALUE h, VALUE pct) {
    return gd_X__gip2_H7(klass, srcImg, dstX, dstY, srcX, srcY, w, h, pct, gdImageCopyMergeGray);
}

#copy_palette(src) ⇒ Object

Copies a palette from an image, attempting to match the colors in the target image to the colors in the source palette.



1474
1475
1476
# File 'ext/rgd/rgd.c', line 1474

static VALUE image_copy_palette(VALUE klass, VALUE img2) {
    return gd_X__gip2(klass, img2, gdImagePaletteCopy);
}

#copy_resampled(src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH) ⇒ Object

Used to copy a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity. The X and Y dimensions of the original region and the destination region can vary, resulting in stretching or shrinking of the region as appropriate. (For a simpler version of this function which does not deal with resizing, see GD::Image.copy. For a version which does not interpolate pixel values, see GD::Image.copy_resized.

Pixel values are only interpolated if the destination image is a truecolor image. Otherwise, GD::Image.copy_resized is automatically invoked.

The dst argument is the destination image to which the region will be copied. The src argument is the source image from which the region is copied. The dstX and dstY arguments specify the point in the destination image to which the region will be copied. The srcX and srcY arguments specify the upper left corner of the region in the source image. The dstW and dstH arguments specify the width and height of the destination region. The srcW and srcH arguments specify the width and height of the source region and can differ from the destination size, allowing a region to be scaled during the copying process.

When you copy a region from one location in an image to another location in the same image, GD::Image.copy will perform as expected unless the regions overlap, in which case the result is unpredictable. If this presents a problem, create a scratch image in which to keep intermediate results.

Important note on copying between images: since images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. If the destination image is a palette image, gd will use the Image.color_resolve function to determine the best color available.



1640
1641
1642
# File 'ext/rgd/rgd.c', line 1640

static VALUE image_copy_resampled(VALUE klass, VALUE srcImg, VALUE  dstX, VALUE  dstY, VALUE  srcX, VALUE  srcY, VALUE  dstW, VALUE  dstH, VALUE  srcW, VALUE  srcH) {
    return gd_X__gip2_H8(klass, srcImg, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH, gdImageCopyResampled);
}

#copy_resized(src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH) ⇒ Object

Used to copy a rectangular portion of one image to another image. The X and Y dimensions of the original region and the destination region can vary, resulting in stretching or shrinking of the region as appropriate. (For a simpler version of this function which does not deal with resizing, see Image.copy.)

The dst argument is the destination image to which the region will be copied. The src argument is the source image from which the region is copied. The dstX and dstY arguments specify the point in the destination image to which the region will be copied. The srcX and srcY arguments specify the upper left corner of the region in the source image. The dstW and dstH arguments specify the width and height of the destination region. The srcW and srcH arguments specify the width and height of the source region and can differ from the destination size, allowing a region to be scaled during the copying process.

When you copy a region from one location in an image to another location in the same image, Image.copy will perform as expected unless the regions overlap, in which case the result is unpredictable. If this presents a problem, create a scratch image in which to keep intermediate results.

Important note on copying between images: since images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. Image.copy will attempt to find an identical RGB value in the destination image for each pixel in the copied portion of the source image by invoking Image.color_exact. If such a value is not found, Image.copy will attempt to allocate colors as needed using Image.color_allocate. If both of these methods fail, Image.copy will invoke Image.color_closest to find the color in the destination image which most closely approximates the color of the pixel being copied.



1601
1602
1603
# File 'ext/rgd/rgd.c', line 1601

static VALUE image_copy_resized(VALUE klass, VALUE srcImg, VALUE dstX, VALUE dstY, VALUE srcX, VALUE srcY, VALUE dstW, VALUE dstH, VALUE srcW, VALUE srcH) {
    return gd_X__gip2_H8(klass, srcImg, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH, gdImageCopyResized);
}

#copy_rotated(src, dstX, dstY, srcX, srcY, srcW, srcH, angle) ⇒ Object

Used to copy a rectangular portion of one image to another image, or to another region of the same image. The srcX and srcY coordinates specify the upper left corner of the source area; however, the dstX and dstY coordinates specify the CENTER of the destination area. This important distinction is made because the rotated rectangle may may or may not be parallel to the X and Y axes. The destination coordinates may be floating point, as the center of the desired destination area may lie at the center of a pixel (0.5 pixels) rather than its upper left corner. The angle specified is an integer number of degrees, between 0 and 360, with 0 degrees causing no change, and counterclockwise rotation as the angle increases.

When you copy a region from one location in an image to another location in the same image, this method will perform as expected unless the regions overlap, in which case the result is unpredictable. If this presents a problem, create a scratch image in which to keep intermediate results.

Important note on copying between images: since palette-based images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. If the destination image is not a truecolor image, Image.color_resolve is used to choose the destination pixel.



1670
1671
1672
1673
1674
1675
1676
# File 'ext/rgd/rgd.c', line 1670

static VALUE image_copy_rotated(VALUE klass, VALUE srcImg, VALUE dstX, VALUE dstY, VALUE srcX, VALUE srcY, VALUE srcW, VALUE srcH, VALUE angle) {
    gdImagePtr dst, src;
    Data_Get_Struct(klass, gdImage, dst);
    Data_Get_Struct(srcImg, gdImage, src);
    gdImageCopyRotated(dst, src, NUM2DBL(dstX), NUM2DBL(dstY), NUM2INT(srcX), NUM2INT(srcY), NUM2INT(srcW), NUM2INT(srcH), NUM2INT(angle));
    return klass;
}

#dashed_line(x1, y1, x2, y2, color) ⇒ Object

Provided solely for backwards compatibility with gd 1.0. New programs should draw dashed lines using the normal Image.line and the new Image.set_style.

This method is used to draw a dashed line between two endpoints (x1,y1 and x2, y2). The line is drawn using the color index specified. The portions of the line that are not drawn are left transparent so the background is visible.



2002
2003
2004
# File 'ext/rgd/rgd.c', line 2002

static VALUE image_dashed_line(VALUE klass, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE color) {
    return gd_X__gip_H5(klass, x1, y1, x2, y2, color, gdImageDashedLine);
}

#data(format, [more params]) ⇒ Object

Convert the image to a byte-string in specified format.

Usage:

  • data(“jpeg”, quality = -1)

  • data(“png”, level = -1)

  • data(“gif”)

  • data(“bmp”)

  • data(“gd2”, chunk_size = 0, fmt = GD2_FMT_COMPRESSED)

  • data(“gd”)

  • data(“wbmp”, fg = 1)



2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
# File 'ext/rgd/rgd.c', line 2713

static VALUE image_data(int argc, VALUE* argv, VALUE klass) {
    VALUE format, a1, a2;
    ImageFormat i_fmt;

    rb_scan_args(argc, argv, "12", &format, &a1, &a2);
    Check_Type(format, T_STRING);
    if (RTEST(a1)) Check_Type(a1, T_FIXNUM);
    if (RTEST(a2)) Check_Type(a2, T_FIXNUM);

    i_fmt = m_image_detect_format_by_ext(RSTRING_PTR(format));
    switch (i_fmt) {
        case FMT_JPEG:
            SetIntIfQnil(a1, -1);
            return rb_funcall(klass, rb_intern("jpeg_data"), 1, a1);
        case FMT_GIF:
            return image_gif_data(klass);
        case FMT_PNG:
            SetIntIfQnil(a1, -1);
            return rb_funcall(klass, rb_intern("png_data"), 1, a1);
        case FMT_BMP:
            return image_bmp_data(klass);
        case FMT_GD2:
            SetIntIfQnil(a1, 0);
            SetIntIfQnil(a2, GD2_FMT_COMPRESSED);
            return rb_funcall(klass, rb_intern("gd2_data"), 2, a1, a2);
        case FMT_GD:
            return image_gd_data(klass);
        case FMT_WBMP:
            SetIntIfQnil(a1, 1);
            return rb_funcall(klass, rb_intern("wbmp_data"), 1, a1);
        case FMT_XBM:
            rb_raise(rb_eRGDError, "This method doesn't support XBM format");
        case FMT_XPM:
            rb_raise(rb_eRGDError, "This method doesn't support XPM format");
        default:
            rb_raise(rb_eRGDError, "Unknown image format.");
    }
}

#file(filename, format = nil, [more params]) ⇒ Object

Write the image to filename in specified format. If format is nil, the file format will be detected automatically by the extension of filename.

Usage:

  • file(filename, “jpeg”, quality = -1)

  • file(filename, “png”, level = -1)

  • file(filename, “gif”)

  • file(filename, “bmp”)

  • file(filename, “gd2”, chunk_size = 0, fmt = GD2_FMT_COMPRESSED)

  • file(filename, “gd”)

  • file(filename, “wbmp”, fg = 1)



2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
# File 'ext/rgd/rgd.c', line 2647

static VALUE image_file(int argc, VALUE* argv, VALUE klass) {
    VALUE filename, format, a1, a2;
    char *ext;
    ImageFormat i_fmt = FMT_UNKNOW;

    rb_scan_args(argc, argv, "13", &filename, &format, &a1, &a2);
    Check_Type(filename, T_STRING);
    if (RTEST(a1)) Check_Type(a1, T_FIXNUM);
    if (RTEST(a2)) Check_Type(a2, T_FIXNUM);

    if (RTEST(format)) {
        Check_Type(format, T_STRING);
        i_fmt = m_image_detect_format_by_ext(RSTRING_PTR(format));
    } else {
        ext = strrchr(RSTRING_PTR(filename), '.');
        if (ext && strlen(ext) > 1) {
            ext += 1;
            i_fmt = m_image_detect_format_by_ext(ext);
        }
    }

    switch (i_fmt) {
        case FMT_JPEG:
            SetIntIfQnil(a1, -1);
            return rb_funcall(klass, rb_intern("jpeg"), 2, filename, a1);
        case FMT_GIF:
            return image_gif(klass, filename);
        case FMT_PNG:
            SetIntIfQnil(a1, -1);
            return rb_funcall(klass, rb_intern("png"), 2, filename, a1);
        case FMT_BMP:
            return image_bmp(klass, filename);
        case FMT_GD2:
            SetIntIfQnil(a1, 0);
            SetIntIfQnil(a2, GD2_FMT_COMPRESSED);
            return rb_funcall(klass, rb_intern("gd2"), 3, filename, a1, a2);
        case FMT_GD:
            return image_gd(klass, filename);
        case FMT_WBMP:
            SetIntIfQnil(a1, 1);
            return rb_funcall(klass, rb_intern("wbmp"), 2, filename, a1);
        case FMT_XBM:
            rb_raise(rb_eRGDError, "This method doesn't support XBM format");
        case FMT_XPM:
            rb_raise(rb_eRGDError, "This method doesn't support XPM format");
        default:
            rb_raise(rb_eRGDError, "Unknown image format.");
    }
}

#fill(x, y, color) ⇒ Object

Floods a portion of the image with the specified color, beginning at the specified point and flooding the surrounding region of the same color as the starting point. For a way of flooding a region defined by a specific border color rather than by its interior color, see Image.fill_to_border.

The fill color can be COLOR_TILED, resulting in a tile fill using another image as the tile. However, the tile image cannot be transparent. If the image you wish to fill with has a transparent color index, call Image.transparent= and set the transparent color index to -1 to turn off its transparency.

Note, this method is recursive. It is not the most naive implementation possible, and the implementation is expected to improve, but there will always be degenerate cases in which the stack can become very deep. This can be a problem in MSDOS and MS Windows environments. (Of course, in a Unix or Windows 95/98/NT environment with a proper stack, this is not a problem at all.)



1918
1919
1920
# File 'ext/rgd/rgd.c', line 1918

static VALUE image_fill(VALUE klass, VALUE x, VALUE y, VALUE color) {
    return gd_X__gip_H3(klass, x, y, color, gdImageFill);
}

#fill_to_border(x, y, border, color) ⇒ Object

Floods a portion of the image with the specified color, beginning at the specified point and stopping at the specified border color. For a way of flooding an area defined by the color of the starting point, see Image.fill.

The border color cannot be a special color such as COLOR_TILED; it must be a proper solid color. The fill color can be, however.

Note, this method is recursive. It is not the most naive implementation possible, and the implementation is expected to improve, but there will always be degenerate cases in which the stack can become very deep. This can be a problem in MSDOS and MS Windows 3.1 environments. (Of course, in a Unix or Windows 95/98/NT environment with a proper stack, this is not a problem at all.)



1947
1948
1949
# File 'ext/rgd/rgd.c', line 1947

static VALUE image_fill_to_border(VALUE klass, VALUE x, VALUE y, VALUE border, VALUE color) {
    return gd_X__gip_H4(klass, x, y, border, color, gdImageFillToBorder);
}

#filled_arc(cx, cy, w, h, s, e, color, style) ⇒ Object

Used to draw a partial ellipse centered at the given point, with the specified width and height in pixels. The arc begins at the position in degrees specified by s and ends at the position specified by e. The arc is filled in the color specified by the second to last argument. A circle can be drawn by beginning from 0 degrees and ending at 360 degrees, with width and height being equal. e must be greater than s. Values greater than 360 are interpreted modulo 360. The last argument is a bitwise OR of the following possibilities:

  • STYLE_ARC

  • STYLE_CHORD

  • STYLE_PIE (synonym for STYLE_CHORD)

  • STYLE_NO_FILL

  • STYLE_EDGED

STYLE_ARC and STYLE_CHORD are mutually exclusive; STYLE_CHORD just connects the starting and ending angles with a straight line, while STYLE_ARC produces a rounded edge. STYLE_PIE is a synonym for STYLE_ARC. STYLE_NO_FILL indicates that the arc or chord should be outlined, not filled. STYLE_EDGED, used together with STYLE_NO_FILL, indicates that the beginning and ending angles should be connected to the center; this is a good way to outline (rather than fill) a ‘pie slice’.



2088
2089
2090
2091
2092
# File 'ext/rgd/rgd.c', line 2088

static VALUE image_filled_arc(VALUE klass, VALUE cx, VALUE cy, VALUE w, VALUE h, VALUE s, VALUE e, VALUE color, VALUE style) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    gdImageFilledArc(im, NUM2INT(cx), NUM2INT(cy), NUM2INT(w), NUM2INT(h), NUM2INT(s), NUM2INT(e), NUM2INT(color), NUM2INT(style));
}

#filled_ellipse(x1, y1, x2, y2, color) ⇒ Object

Used to draw an ellipse centered at the given point, with the specified width and height in pixels. The ellipse is filled in the color specified by the last argument.



2036
2037
2038
# File 'ext/rgd/rgd.c', line 2036

static VALUE image_filled_ellipse(VALUE klass, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE color) {
    return gd_X__gip_H5(klass, x1, y1, x2, y2, color, gdImageFilledEllipse);
}

#filled_polygon(points, color) ⇒ Object

Used to fill a polygon with the verticies (at least 3) specified, using the color index specified. points is an array looks like [[1, 1], [2, 2], [3, 3]].

See also Image.polygon.



2212
2213
2214
# File 'ext/rgd/rgd.c', line 2212

static VALUE image_filled_polygon(VALUE klass, VALUE points, VALUE color) {
    return gd_X__gip_gptp_H2(klass, points, color, gdImageFilledPolygon);
}

#filled_rectangle(x1, y1, x2, y2, color) ⇒ Object

Used to fill a polygon with the verticies (at least 3) specified, using the color index specified. See also Image.polygon.



2024
2025
2026
# File 'ext/rgd/rgd.c', line 2024

static VALUE image_filled_rectangle(VALUE klass, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE color) {
    return gd_X__gip_H5(klass, x1, y1, x2, y2, color, gdImageFilledRectangle);
}

#gd(filename) ⇒ Object

Write the image to the specified file in GD format.



751
752
753
# File 'ext/rgd/rgd.c', line 751

static VALUE image_gd(VALUE klass, VALUE filename) {
    return gd_image_to_file(klass, filename, gdImageGd);
}

#gd2(filename, chunk_size = 0, fmt = GD2_FMT_COMPRESSED) ⇒ Object

Write the image to the specified file in GD2 format.

The gd2 image format is intended for fast reads and writes of parts of images. It is a compressed format (when fmt is GD2_FMT_COMPRESSED), and well suited to retrieving smll sections of much larger images.

The file is stored as a series of compressed subimages, and the chunk_size determines the sub-image size - a value of zero causes the GD library to use the default.

It is also possible to store GD2 files in an uncompressed format, in which case fmt should be GD2_FMT_RAW.



860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'ext/rgd/rgd.c', line 860

static VALUE image_gd2(int argc, VALUE *argv, VALUE klass) {
    VALUE filename, chunk_size, fmt;
    gdImagePtr im;
    FILE* fp;

    rb_scan_args(argc, argv, "12", &filename, &chunk_size, &fmt);
    SetIntIfQnil(chunk_size, 0);
    SetIntIfQnil(fmt, GD2_FMT_COMPRESSED);
    Check_Type(chunk_size, T_FIXNUM);
    Check_Type(fmt, T_FIXNUM);

    fp = fopen(RSTRING_PTR(filename), "wb");
    if (!fp) rb_raise(rb_eIOError, "Cannot open %s for write", RSTRING_PTR(filename));

    Data_Get_Struct(klass, gdImage, im);
    gdImageGd2(im, fp, NUM2INT(chunk_size), NUM2INT(fmt));
    fclose(fp);
    return klass;
}

#gd2_data(chunk_size = 0, fmt = GD2_FMT_COMPRESSED) ⇒ Object

Convert the image to a GD2 format byte-string.

Read Image.gd2 for more.



1010
1011
1012
1013
1014
1015
1016
# File 'ext/rgd/rgd.c', line 1010

static VALUE image_gd2_data(int argc, VALUE *argv, VALUE klass) {
    VALUE a, b;
    rb_scan_args(argc, argv, "02", &a, &b);
    SetIntIfQnil(a, 0);
    SetIntIfQnil(b, GD2_FMT_COMPRESSED);
    return gd_image_to_data_H2(klass, a, b, gd_gdImageGd2Ptr);
}

#gd_dataObject

Convert the image to a GD format byte-string.



910
911
912
# File 'ext/rgd/rgd.c', line 910

static VALUE image_gd_data(VALUE klass) {
    return gd_image_to_data(klass, gdImageGdPtr);
}

#gif(filename) ⇒ Object

Write the image to the specified file in GIF format.



741
742
743
# File 'ext/rgd/rgd.c', line 741

static VALUE image_gif(VALUE klass, VALUE filename) {
    return gd_image_to_file(klass, filename, gdImageGif);
}

#gif_anim_add_data(local_cm = 1, left = 0, top = 0, delay = 5, disposal = DISPOSAL_NONE, prev_image = nil) ⇒ Object

This function returns GIF animation frames to GIF animation, which was initialized with Image.gif_anim_begin_data.

With left and top you can place this frame in different offset than (0,0) inside the image screen as defined in Image.gif_anim_begin_data.

The argument delay between the previous frame and this frame is in 1/100s units.

The argument disposal is usually DISPOSAL_NONE, meaning that the pixels changed by this frame should remain on the display when the next frame begins to render, but can also be DISPOSAL_RESTORE_BACKGROUND (restores the first allocated color of the global palette), or DISPOSAL_RESTORE_PREVIOUS (restores the appearance of the affected area before the frame was rendered). Only DISPOSAL_NONE is a sensible choice for the first frame.

If prev_im is not nil, the built-in GIF optimizer will always use DISPOSAL_NONE regardless of the Disposal parameter.



1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
# File 'ext/rgd/rgd.c', line 1075

static VALUE image_gif_anim_add_data(int argc, VALUE *argv, VALUE klass) {
    VALUE data, local_cm, left, top, delay, disposal, prev_image;
    gdImagePtr im, im2 = NULL;
    char* buf;
    int len;

    rb_scan_args(argc, argv, "06", &local_cm, &left, &top, &delay, &disposal, &prev_image);
    SetIntIfQnil(local_cm, 1);
    SetIntIfQnil(left, 0);
    SetIntIfQnil(top, 0);
    SetIntIfQnil(delay, 5);
    SetIntIfQnil(disposal, gdDisposalNone);
    if RTEST(prev_image) Data_Get_Struct(prev_image, gdImage, im2);

    Data_Get_Struct(klass, gdImage, im);
    buf = gdImageGifAnimAddPtr(im, &len, NUM2INT(local_cm), NUM2INT(left), NUM2INT(top), NUM2INT(delay), NUM2INT(disposal), im2);
    data = rb_str_new(buf, len);
    gdFree(buf);
    return data;
}

#gif_anim_begin_data(global_cm = -1, loops = 0) ⇒ Object

This function must be called as the first function when creating a GIF animation. It returns a byte-string for the correct GIF file headers, and prepares for frames to be added for the animation. It’s NOT used to produce an image frame of GIF file, it is only used to establish the GIF animation frame size, interlacing options and the color palette. Image.gif_anim_add_data is used to make the first and subsequent frames to the animation, and the animation must be terminated by writing a semicolon character (;) to it or by using Image.gif_anim_end_data to get that.

The global_cm flag indicates if a global color map (or palette) is used in the GIF89A header. A nonzero value specifies that a global color map should be used to reduce the size of the animation. Of course, if the color maps of individual frames differ greatly, a global color map may not be a good idea. global_cm=1 means write global color map, global_cm=0 means do not, and global_cm=-1 means to do the default, which currently is to use a global color map.

If loops is 0 or greater, the Netscape 2.0 extension for animation loop count is written. 0 means infinite loop count. -1 means that the extension is not added which results in no looping.



1043
1044
1045
1046
1047
1048
1049
# File 'ext/rgd/rgd.c', line 1043

static VALUE image_gif_anim_begin_data(int argc, VALUE *argv, VALUE klass) {
    VALUE a, b;
    rb_scan_args(argc, argv, "02", &a, &b);
    SetIntIfQnil(a, -1);
    SetIntIfQnil(b, 0);
    return gd_image_to_data_H2(klass, a, b, gdImageGifAnimBeginPtr);
}

#gif_anim_end_dataObject

Returns a one byte string containing the semicolon character (;). The string “;” can be used in place of this function.



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'ext/rgd/rgd.c', line 1104

static VALUE image_gif_anim_end_data(VALUE klass) {
    VALUE data;
    char* buf;
    int len;

    buf = gdImageGifAnimEndPtr(&len);
    data = rb_str_new(buf, len);
    gdFree(buf);
    return data;
}

#gif_dataObject

Convert the image to a GIF format byte-string.



900
901
902
# File 'ext/rgd/rgd.c', line 900

static VALUE image_gif_data(VALUE klass) {
    return gd_image_to_data(klass, gdImageGifPtr);
}

#heightObject

Get the height of the image in pixels.



1152
1153
1154
1155
1156
# File 'ext/rgd/rgd.c', line 1152

static VALUE image_sy(VALUE klass) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    return INT2NUM(gdImageSY(im));
}

#interlaceObject

Read Image.interlace= for details.



1188
1189
1190
1191
1192
# File 'ext/rgd/rgd.c', line 1188

static VALUE image_get_interlace(VALUE klass) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    return gdImageGetInterlaced(im) ? Qtrue : Qfalse;
}

#interlace=(boolean) ⇒ Object

Used to determine whether an image should be stored in a linear fashion, in which lines will appear on the display from first to last, or in an interlaced fashion, in which the image will “fade in” over several passes. By default, images are not interlaced. (When writing JPEG images, interlacing implies generating progressive JPEG files, which are represented as a series of scans of increasing quality. Noninterlaced gd images result in regular (sequential) JPEG data streams.)

Note that interlace has no effect on other functions, and has no meaning unless you save the image in PNG or JPEG format.



1700
1701
1702
# File 'ext/rgd/rgd.c', line 1700

static VALUE image_interlace_set(VALUE klass, VALUE interlace) {
    return gd_X__gip_H(klass, RTEST(interlace) ? INT2NUM(1) : INT2NUM(0), gdImageInterlace);
}

#jpeg(filename, quality = -1) ⇒ Object

Write the image to the specified file in JPEG format.

If quality is negative, the default IJG JPEG quality value (which should yield a good general quality / size tradeoff for most situations) is used. Otherwise, for practical purposes, quality should be a value in the range 0-95, higher quality values usually implying both higher quality and larger image sizes.



784
785
786
787
788
789
# File 'ext/rgd/rgd.c', line 784

static VALUE image_jpeg(int argc, VALUE *argv, VALUE klass) {
    VALUE filename, quality;
    rb_scan_args(argc, argv, "11", &filename, &quality);
    SetIntIfQnil(quality, -1);
    return gd_image_to_file_H(klass, filename, quality, gdImageJpeg);
}

#jpeg_data(quality = -1) ⇒ Object

Convert the image to a JPEG format byte-string.

Read Image.jpeg for more.



936
937
938
939
940
941
# File 'ext/rgd/rgd.c', line 936

static VALUE image_jpeg_data(int argc, VALUE *argv, VALUE klass) {
    VALUE a;
    rb_scan_args(argc, argv, "01", &a);
    SetIntIfQnil(a, -1);
    return gd_image_to_data_H(klass, a, gdImageJpegPtr);
}

#line(x1, y1, x2, y2, color) ⇒ Object

Used to draw a line between two endpoints (x1,y1 and x2, y2). The line is drawn using the color index specified. Note that the color index can be an actual color returned by Image.color_allocate or one of COLOR_STYLED, COLOR_BRUSHED or COLOR_STYLED_BRUSHED.



1986
1987
1988
# File 'ext/rgd/rgd.c', line 1986

static VALUE image_line(VALUE klass, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE color) {
    return gd_X__gip_H5(klass, x1, y1, x2, y2, color, gdImageLine);
}

#open_polygon(points, color) ⇒ Object

Used to draw a sequence of lines with the verticies (at least 3) specified, using the color index specified. points is an array looks like [[1, 1], [2, 2], [3, 3]]. Unlike Image.polygon, the enpoints of the line sequence are not connected to a closed polygon.



2199
2200
2201
# File 'ext/rgd/rgd.c', line 2199

static VALUE image_open_polygon(VALUE klass, VALUE points, VALUE color) {
    return gd_X__gip_gptp_H2(klass, points, color, gdImageOpenPolygon);
}

#png(filename, level = -1) ⇒ Object

Write the image to the specified file in PNG format.

level specified the level of compression to be specified. A compression level of 0 means “no compression.” A compression level of 1 means “compressed, but as quickly as possible.” A compression level of 9 means “compressed as much as possible to produce the smallest possible file.” A compression level of -1 will use the default compression level at the time zlib was compiled on your system.



804
805
806
807
808
809
# File 'ext/rgd/rgd.c', line 804

static VALUE image_png(int argc, VALUE *argv, VALUE klass) {
    VALUE filename, level;
    rb_scan_args(argc, argv, "11", &filename, &level);
    SetIntIfQnil(level, -1);
    return gd_image_to_file_H(klass, filename, level, gdImagePngEx);
}

#png_data(level = -1) ⇒ Object

Convert the image to a PNG format byte-string.

Read Image.png for more.



951
952
953
954
955
956
# File 'ext/rgd/rgd.c', line 951

static VALUE image_png_data(int argc, VALUE *argv, VALUE klass) {
    VALUE a;
    rb_scan_args(argc, argv, "01", &a);
    SetIntIfQnil(a, -1);
    return gd_image_to_data_H(klass, a, gdImagePngPtrEx);
}

#polygon(points, color) ⇒ Object

Used to draw a polygon with the verticies (at least 3) specified, using the color index specified. points is an array looks like [[1, 1], [2, 2], [3, 3]].

See also Image.filled_polygon.



2186
2187
2188
# File 'ext/rgd/rgd.c', line 2186

static VALUE image_polygon(VALUE klass, VALUE points, VALUE color) {
    return gd_X__gip_gptp_H2(klass, points, color, gdImagePolygon);
}

#rectangle(x1, y1, x2, y2, color) ⇒ Object

Used to draw a rectangle with the two corners (upper left first, then lower right) specified, using the color index specified.



2013
2014
2015
# File 'ext/rgd/rgd.c', line 2013

static VALUE image_rectangle(VALUE klass, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE color) {
    return gd_X__gip_H5(klass, x1, y1, x2, y2, color, gdImageRectangle);
}

#rObject

Returns a array containing the red, green, blue, alpha components of the specified color (for truecolor image) or color index (for palette-based image).



1217
1218
1219
1220
1221
1222
# File 'ext/rgd/rgd.c', line 1217

static VALUE image_rgba(VALUE klass, VALUE color) {
    gdImagePtr im;
    int c = NUM2INT(color);
    Data_Get_Struct(klass, gdImage, im);
    return rb_ary_new3(4, INT2NUM(gdImageRed(im, c)), INT2NUM(gdImageGreen(im, c)), INT2NUM(gdImageBlue(im, c)), INT2NUM(gdImageAlpha(im, c)));
}

#save_alpha=(boolean) ⇒ Object

By default, gd 2.0.2 and above do not attempt to save full alpha channel information (as opposed to single-color transparency) when saving PNG images. (PNG is currently the only output format supported by gd which can accommodate alpa channel information.) This saves space in the output file. If you wish to create an image with alpha channel information for use with tools that support it, set save_alpha=true to turn on saving of such information, and set alpha_blending=false to turn off alpha blending within the library so that alpha channel information is actually stored in the image rather than being composited immediately at the time that drawing functions are invoked.



1776
1777
1778
# File 'ext/rgd/rgd.c', line 1776

static VALUE image_save_alpha(VALUE klass, VALUE save) {
    return gd_X__gip_H(klass, RTEST(save) ? INT2NUM(1) : INT2NUM(0), gdImageSaveAlpha);
}

#sharepen(pct) ⇒ Object

Sharpens the specified image. pct is a sharpening percentage, and can be greater than 100. Silently does nothing to non-truecolor images. Silently does nothing for pct<0. Transparency/alpha channel are not altered.



1826
1827
1828
# File 'ext/rgd/rgd.c', line 1826

static VALUE image_sharepen(VALUE klass, VALUE pct) {
    return gd_X__gip_H(klass, pct, gdImageSharpen);
}

#string(font, x, y, str, color) ⇒ Object

Used to draw multiple characters on the image. (To draw single characters, use #char.)

The string specified by the fifth argument str is drawn from left to right in the specified color. (See #string_up for a way of drawing vertical text. See also #stringft for a high quality solution.) Pixels not set by a particular character retain their previous color.



2253
2254
2255
# File 'ext/rgd/rgd.c', line 2253

static VALUE image_string(VALUE klass, VALUE font, VALUE x, VALUE y, VALUE str, VALUE color) {
    return gd_image_string(klass, font, x, y, str, color, gdImageString);
}

#string_up(font, x, y, str, color) ⇒ Object

Used to draw multiple characters on the image, rotated 90 degrees. (To draw single characters, use Image.char_up.)

The argument str is drawn from bottom to top (rotated 90 degrees) in the specified color. (See Image.string for a way of drawing horizontal text.) Pixels not set by a particular character retain their previous color.



2268
2269
2270
# File 'ext/rgd/rgd.c', line 2268

static VALUE image_string_up(VALUE klass, VALUE font, VALUE x, VALUE y, VALUE str, VALUE color) {
    return gd_image_string(klass, font, x, y, str, color, gdImageStringUp);
}

#stringft(fg, fontname, ptsize, angle, x, y, str, opts = {}) ⇒ Object Also known as: text

Draws a string of anti-aliased characters on the image using the FreeType library to render user-supplied TrueType fonts. The string is anti-aliased, meaning that there should be fewer “jaggies” visible. The fontname is the full pathname to a TrueType font file, or a font face name if the GDFONTPATH environment variable or the compiled-in DEFAULT_FONTPATH macro of gdft.c have been set intelligently. In the absence of a full path, the font face name may be presented with or without extension (2.0.26).

The null-terminated string argument is considered to be encoded via the UTF_8 standard; also, HTML entities are supported, including decimal, hexadecimal, and named entities (2.0.26). Those who are passing ordinary ASCII strings may have difficulty with the & character unless encoded correctly as & but should have no other difficulties.

The string may be arbitrarily scaled (ptsize) and rotated (angle in radians). The direction of rotation is counter-clockwise, with 0 radians (0 degrees) at 3 o’clock and PI/2 radians (90 degrees) at 12 o’clock.

The string is rendered in the color indicated by the fg color index. Use the negative of the desired color index to disable anti-aliasing.

The string may contain UTF-8 sequences like: “À”

This method returns a hash object, and the element with key “brect” is an array filled with 4 elements representing the 4 corner coordinates of the bounding rectangle (the smallest rectangle that completely surrounds the rendered string and does not intersect any pixel of the rendered string).

[ [lower_left_X, lower_left_Y], [lower_right_X, lower_right_Y], [upper_right_X, upper_right_Y], [upper_left_X, upper_left_Y] ]

Use Image::stringft to get the bounding rectangle without rendering. This is a relatively cheap operation if followed by a rendering of the same string, because of the caching of the partial rendering during bounding rectangle calculation.

Options:

  • :linespcing => double

  • :charmap => CHARMAP_*

  • :hdpi => integer

  • :vdpi => integer

  • :kerning => boolean

  • :xshow => boolean

  • :fontpath => boolean

  • :fontconfig => boolean

To output multiline text with a specific line spacing, set the option :linespacing to the desired spacing, expressed as a multiple of the font height. Thus a line spacing of 1.0 is the minimum to guarantee that lines of text do not collide. If :linespacing is not present, linespacing defaults to 1.05.

To specify a preference for Unicode, Shift_JIS Big5 character encoding, set the option :charmap to CHARMAP_*. If you do not specify a preference, Unicode will be tried first. If the preferred character mapping is not found in the font, other character mappings are attempted.

GD operates on the assumption that the output image will be rendered to a computer screen. By default, gd passes a resolution of 96 dpi to the freetype text rendering engine. This influences the “hinting” decisions made by the renderer. To specify a different resolution, set :hdpi and :vdpi accordingly (in dots per inch).

GD 2.0.29 and later will normally attempt to apply kerning tables, if fontconfig is available, to adjust the relative positions of consecutive characters more ideally for that pair of characters. This can be turn off by set the option :kerning to false;

GD 2.0.29 and later can return a vector of individual character position advances by set the option :xshow to true, occasionally useful in applications that must know exactly where each character begins. This is returned in the element with key “xshow”.

GD 2.0.29 and later can also return the path to the actual font file used if the option :returnfontpath is true. This is useful because GD 2.0.29 and above are capable of selecting a font automatically based on a fontconfig font pattern when fontconfig is available. This information is returned in the element with key “fontpath”.

GD 2.0.29 and later can use fontconfig to resolve font names, including fontconfig patterns, if the option :fontconfig is true. As a convenience, this behavior can be made the default by calling Image.use_fontconfig=true. In that situation it is not necessary to set the option :fontconfig on every call; however explicit font path names can still be used if the option :fontpathname is true.

Unless Image.use_fontconfig=true has been called, GD 2.0.29 and later will still expect the fontlist argument to the freetype text output functions to be a font file name or list thereof as in previous versions. If you do not wish to make fontconfig the default, it is still possible to force the use of fontconfig for a single call to the freetype text output functions by setting the option :fontconfig to ture.



2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
# File 'ext/rgd/rgd.c', line 2413

static VALUE image_stringft(int argc, VALUE *argv, VALUE klass) {
    VALUE fg, fontname, ptsize, angle, x, y, str, opts;
    VALUE ret, m, n;
    gdImagePtr im = NULL;
    gdFTStringExtra ftex;
    int brect[8];
    char *err;

    if (TYPE(klass) == T_DATA) Data_Get_Struct(klass, gdImage, im);
    memset(&ftex, 0, sizeof(gdFTStringExtra));
    if (rb_scan_args(argc, argv, "71", &fg, &fontname, &ptsize, &angle, &x, &y, &str, &opts) == 7) {
        err = gdImageStringFT(im, &brect[0], NUM2INT(fg), RSTRING_PTR(fontname), NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING_PTR(str));
    } else {
        Check_Type(opts, T_HASH);

        m = rb_hash_aref(opts, STR2SYM("linespacing"));
        if (RTEST(m)) {
            ftex.flags |= gdFTEX_LINESPACE;
            ftex.linespacing = NUM2DBL(m);
        }

        m = rb_hash_aref(opts, STR2SYM("charmp"));
        if (RTEST(m)) {
            ftex.flags |= gdFTEX_CHARMAP;
            ftex.charmap = NUM2INT(m);
        }

        m = rb_hash_aref(opts, STR2SYM("hdpi"));
        n = rb_hash_aref(opts, STR2SYM("vdpi"));
        if (RTEST(m) && RTEST(n)) {
            ftex.flags |= gdFTEX_RESOLUTION;
            ftex.hdpi = NUM2INT(m);
            ftex.vdpi = NUM2INT(n);
        }

        m = rb_hash_aref(opts, STR2SYM("kerning"));
        if (m == Qfalse) ftex.flags |= gdFTEX_DISABLE_KERNING;

        m = rb_hash_aref(opts, STR2SYM("xshow"));
        if (RTEST(m)) ftex.flags |= gdFTEX_XSHOW;

        m = rb_hash_aref(opts, STR2SYM("returnfontpath"));
        if (RTEST(m)) ftex.flags |= gdFTEX_RETURNFONTPATHNAME;

        m = rb_hash_aref(opts, STR2SYM("fontpathname"));
        if (RTEST(m)) ftex.flags |= gdFTEX_FONTPATHNAME;

        m = rb_hash_aref(opts, STR2SYM("fontconfig"));
        if (RTEST(m)) ftex.flags |= gdFTEX_FONTCONFIG;

        err = gdImageStringFTEx(im, &brect[0], NUM2INT(fg), RSTRING_PTR(fontname), NUM2DBL(ptsize), NUM2DBL(angle), NUM2INT(x), NUM2INT(y), RSTRING_PTR(str), &ftex);
    }

    if (err) rb_raise(rb_eRGDError, "%s", err);

    ret = rb_hash_new();
    rb_hash_aset(ret, rb_str_new2("brect"),
        rb_ary_new3(4,
            rb_ary_new3(2, INT2NUM(brect[0]), INT2NUM(brect[1])),
            rb_ary_new3(2, INT2NUM(brect[2]), INT2NUM(brect[3])),
            rb_ary_new3(2, INT2NUM(brect[4]), INT2NUM(brect[5])),
            rb_ary_new3(2, INT2NUM(brect[6]), INT2NUM(brect[7]))
        ));

    if (ftex.flags != 0) {
        if (ftex.xshow) {
            rb_hash_aset(ret, rb_str_new2("xshow"), rb_str_new2(ftex.xshow));
            gdFree(ftex.xshow);
        }

        if (ftex.fontpath) {
            rb_hash_aset(ret, rb_str_new2("fontpath"), rb_str_new2(ftex.fontpath));
            gdFree(ftex.fontpath);
        }
    }

    return ret;
}

#stringft_circle(cx, cy, radius, textRadius, fillPortion, fontname, points, top, bottom, fg) ⇒ Object

Draws the text strings specified by top and bottom on the image, curved along the edge of a circle of radius radius, with its center at cx and cy. top is written clockwise along the top; bottom is written counterclockwise along the bottom. textRadius determines the “height” of each character; if textRadius is 1/2 of radius, characters extend halfway from the edge to the center. fillPortion varies from 0 to 1.0, with useful values from about 0.4 to 0.9, and determines how much of the 180 degrees of arc assigned to each section of text is actually occupied by text; 0.9 looks better than 1.0 which is rather crowded. fontname is a freetype font; see Image.stringft. points is passed to the freetype engine and has an effect on hinting; although the size of the text is determined by radius, textRadius, and fillPortion, you should pass a point size that “hints” appropriately – if you know the text will be large, pass a large point size such as 24.0 to get the best results. fg can be any color, and may have an alpha component, do blending, etc.



2513
2514
2515
2516
2517
2518
2519
2520
# File 'ext/rgd/rgd.c', line 2513

static VALUE image_stringft_circle(VALUE klass, VALUE cx, VALUE cy, VALUE radius, VALUE textRadius, VALUE fillPortion, VALUE fontname, VALUE points, VALUE top, VALUE bottom, VALUE fg) {
    gdImagePtr im;
    char *err;
    Data_Get_Struct(klass, gdImage, im);
    err = gdImageStringFTCircle(im, NUM2INT(cx), NUM2INT(cy), NUM2DBL(radius), NUM2DBL(textRadius), NUM2DBL(fillPortion), RSTRING_PTR(fontname), NUM2DBL(points), RSTRING_PTR(top), RSTRING_PTR(bottom), NUM2INT(fg));
    if (err) rb_raise(rb_eRGDError, "%s", err);
    return klass;
}

#styles=(array) ⇒ Object

It is often desirable to draw dashed lines, dotted lines, and other variations on a broken line. This method can be used to set any desired series of colors, including a special color that leaves the background intact, to be repeated during the drawing of a line.

To use this method, create an array of integers and assign them the desired series of color values to be repeated. You can assign the special color value COLOR_TRANSPARENT to indicate that the existing color should be left unchanged for that particular pixel (allowing a dashed line to be attractively drawn over an existing image).

Then, to draw a line using the style, use the normal Image.line with the special color value COLOR_STYLED.

You can also combine styles and brushes to draw the brush image at intervals instead of in a continuous stroke. When creating a style for use with a brush, the style values are interpreted differently: zero (0) indicates pixels at which the brush should not be drawn, while one (1) indicates pixels at which the brush should be drawn. To draw a styled, brushed line, you must use the special color value COLOR_STYLED_BRUSHED.



2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
# File 'ext/rgd/rgd.c', line 2135

static VALUE image_set_style(VALUE klass, VALUE styles) {
    gdImagePtr im;
    int *ary;
    int i, len;

    Check_Type(styles, T_ARRAY);
    len = RARRAY_LEN(styles);
    ary = malloc(sizeof(int) * len);
    for (i=0;i<len;i++) ary[i] = NUM2INT(rb_ary_entry(styles, i));

    Data_Get_Struct(klass, gdImage, im);
    gdImageSetStyle(im, ary, len);
    free(ary);
    return klass;
}

#thickness=(width) ⇒ Object

This method determines the width of lines drawn by the Image.line, Image.polygon, Image.open_polygon and related methods, in pixels.



1738
1739
1740
# File 'ext/rgd/rgd.c', line 1738

static VALUE image_set_thickness(VALUE klass, VALUE thickness) {
    return gd_X__gip_H(klass, thickness, gdImageSetThickness);
}

#tile=(img) ⇒ Object

A “tile” is an image used to fill an area with a repeated pattern. Any gd image can be used as a tile, and by setting the transparent color index of the tile image with Image.transparent=, a tile that allows certain parts of the underlying area to shine through can be created. All region-filling functions, such as Image.fill and Image.filled_polygon, will use the current tile if the special “color” COLOR_TILED is used when calling them.

This is method is used to specify the tile to be used in a particular image. You can set any image to be the tile. If the tile image does not have the same color map as the first image, any colors missing from the first image will be allocated. If not enough colors can be allocated, the closest colors already available will be used. This allows arbitrary PNGs to be used as tile images. It also means, however, that you should not set a tile unless you will actually use it; if you set a rapid succession of different tile images, you can quickly fill your color map, and the results will not be optimal.



1463
1464
1465
# File 'ext/rgd/rgd.c', line 1463

static VALUE image_set_tile(VALUE klass, VALUE img2) {
    return gd_X__gip2(klass, img2, gdImageSetTile);
}

#to_palette(dither = true, colors = MAX_COLORS) ⇒ Object

Create a new palette-based image from current. If the image is a palette-based image already, this method equals to RGD::Image.clone.



2774
2775
2776
2777
2778
2779
2780
2781
# File 'ext/rgd/rgd.c', line 2774

static VALUE image_to_palette(int argc, VALUE* argv, VALUE klass) {
    VALUE nimage = image_clone(klass);
    if (image_is_truecolor(nimage) == Qfalse) {
        return nimage;
    } else {
        return image_truecolor_to_palette(argc, argv, nimage);
    }
}

#to_palette!(dither = true, colors = MAX_COLORS) ⇒ Object

Convert a truecolor image to a palette-based image, using a high-quality two-pass quantization routine.

If dither is true, the image will be dithered to approximate colors better, at the expense of some obvious “speckling.” colors can be anything up to 256. If the original source image includes photographic information or anything that came out of a JPEG, 256 is strongly recommended. 100% transparency of a single transparent color in the original truecolor image will be preserved. There is no other support for preservation of alpha channel or transparency in the destination image.



1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
# File 'ext/rgd/rgd.c', line 1852

static VALUE image_truecolor_to_palette(int argc, VALUE* argv, VALUE klass) {
    VALUE dither, colors;

    if (image_is_truecolor(klass) == Qfalse) return klass;

    rb_scan_args(argc, argv, "02", &dither, &colors);
    return gd_X__gip_H2(klass,
            (dither == Qnil || dither == Qtrue ? INT2NUM(1) : INT2NUM(0)),
            (colors == Qnil ? INT2NUM(gdMaxColors) : colors),
            gdImageTrueColorToPalette);
}

#transparentObject

Returns the current transparent color index in the image. If there is no transparent color returns -1.



1202
1203
1204
1205
1206
# File 'ext/rgd/rgd.c', line 1202

static VALUE image_transparent_get(VALUE klass) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    return INT2NUM(gdImageGetTransparent(im));
}

#transparent=(color) ⇒ Object

Set the transparent color index for the specified image to the specified index. To indicate that there should be no transparent color, invoke this method with a color index of -1. Note that JPEG images do not support transparency, so this setting has no effect when writing JPEG images.

The color index used should be an index allocated by Image.color_allocate, whether explicitly invoked by your code or implicitly invoked by loading an image. In order to ensure that your image has a reasonable appearance when viewed by users who do not have transparent background capabilities (or when you are writing a JPEG-format file, which does not support transparency), be sure to give reasonable RGB values to the color you allocate for use as a transparent color, even though it will be transparent on systems that support PNG transparency.



1798
1799
1800
# File 'ext/rgd/rgd.c', line 1798

static VALUE image_color_transparent(VALUE klass, VALUE color) {
    return gd_X__gip_H(klass, color, gdImageColorTransparent);
}

#truecolor?Boolean

Return true if the image is a truecolor image, false for palette-based image.

Returns:

  • (Boolean)


1164
1165
1166
1167
1168
# File 'ext/rgd/rgd.c', line 1164

static VALUE image_is_truecolor(VALUE klass) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    return gdImageTrueColor(im) != 0 ? Qtrue : Qfalse;
}

#wbmp(filename, fg = 1) ⇒ Object

Write the image to the specified file in WBMP format.

WBMP file support is black and white only. The color index specified by the fg argument is the “foreground,” and only pixels of this color will be set in the WBMP file. All other pixels will be considered “background.”



835
836
837
838
839
840
# File 'ext/rgd/rgd.c', line 835

static VALUE image_wbmp(int argc, VALUE *argv, VALUE klass) {
    VALUE filename, fg;
    rb_scan_args(argc, argv, "11", &filename, &fg);
    SetIntIfQnil(fg, 1);
    return gd_image_to_file_H(klass, filename, fg, gd_gdImageWBMP);
}

#wbmp_data(fg = 1) ⇒ Object

Convert the image to a WBMP format byte-string.

Read Image.wbmp for more.



966
967
968
969
970
971
# File 'ext/rgd/rgd.c', line 966

static VALUE image_wbmp_data(int argc, VALUE *argv, VALUE klass) {
    VALUE a;
    rb_scan_args(argc, argv, "01", &a);
    SetIntIfQnil(a, 1);
    return gd_image_to_data_H(klass, a, gdImageWBMPPtr);
}

#widthObject

Get the width of the image in pixels.



1140
1141
1142
1143
1144
# File 'ext/rgd/rgd.c', line 1140

static VALUE image_sx(VALUE klass) {
    gdImagePtr im;
    Data_Get_Struct(klass, gdImage, im);
    return INT2NUM(gdImageSX(im));
}