ruby-libgd 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/gd/gd.c +0 -1
- data/ext/gd/gd.o +0 -0
- data/ext/gd/gd.so +0 -0
- data/ext/gd/image.c +10 -6
- data/ext/gd/image.o +0 -0
- data/ext/gd/ruby_gd.h +0 -1
- data/ext/gd/text.c +103 -6
- data/ext/gd/text.o +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 86d2d815f83b82844f6e052eedcd00481e53bf8d270dc8db48a5c4bc18bcecbb
|
|
4
|
+
data.tar.gz: fd3bea0c6cbeb6d6bc5d0f31716b0c32d57b62f3cad20f7955cbe695360bb87c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1389a01c9e0de55a8a2aad3cda2781016c292fe6ddc44aebcb768f89e73c103f6a28466a253e92466f84990ea22e28cd76432464aa19f8a4894ad5d3d59a15bd
|
|
7
|
+
data.tar.gz: 68453f430c861714bf37ce2c2c7016cafb22543f19d5c22c964d303c6c4bf163ee4d50ac3370ee37551c1e206aec6dff03897036052c2cde94cb2b7a9cd7aad5
|
data/ext/gd/gd.c
CHANGED
data/ext/gd/gd.o
CHANGED
|
Binary file
|
data/ext/gd/gd.so
CHANGED
|
Binary file
|
data/ext/gd/image.c
CHANGED
|
@@ -274,18 +274,20 @@ static VALUE gd_image_antialias(VALUE self, VALUE flag) {
|
|
|
274
274
|
gd_image_wrapper *wrap;
|
|
275
275
|
TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
|
|
276
276
|
|
|
277
|
+
if (!wrap->img)
|
|
278
|
+
rb_raise(rb_eRuntimeError, "image is NULL");
|
|
279
|
+
|
|
277
280
|
if (RTEST(flag)) {
|
|
278
|
-
|
|
281
|
+
int aa = gdTrueColorAlpha(255,255,255,0);
|
|
282
|
+
gdImageSetAntiAliased(wrap->img, aa);
|
|
283
|
+
gdImageAlphaBlending(wrap->img, 1);
|
|
279
284
|
} else {
|
|
280
285
|
gdImageSetAntiAliased(wrap->img, -1);
|
|
281
286
|
}
|
|
282
287
|
|
|
283
|
-
return
|
|
288
|
+
return flag;
|
|
284
289
|
}
|
|
285
290
|
|
|
286
|
-
void gd_define_antialias(VALUE cGDImage) {
|
|
287
|
-
rb_define_method(cGDImage, "antialias", gd_image_antialias, 1);
|
|
288
|
-
}
|
|
289
291
|
|
|
290
292
|
void gd_define_image(VALUE mGD) {
|
|
291
293
|
VALUE cGDImage = rb_define_class_under(mGD, "Image", rb_cObject);
|
|
@@ -302,5 +304,7 @@ void gd_define_image(VALUE mGD) {
|
|
|
302
304
|
rb_define_singleton_method(cGDImage, "new_true_color", gd_image_s_new_true_color, 2);
|
|
303
305
|
rb_define_method(cGDImage, "alpha_blending=", gd_image_alpha_blending, 1);
|
|
304
306
|
rb_define_method(cGDImage, "save_alpha=", gd_image_save_alpha, 1);
|
|
305
|
-
rb_define_method(cGDImage, "antialias", gd_image_antialias, 1);
|
|
307
|
+
rb_define_method(cGDImage, "antialias=", gd_image_antialias, 1);
|
|
308
|
+
rb_define_method(cGDImage, "antialias", gd_image_antialias, 1);
|
|
309
|
+
|
|
306
310
|
}
|
data/ext/gd/image.o
CHANGED
|
Binary file
|
data/ext/gd/ruby_gd.h
CHANGED
|
@@ -17,7 +17,6 @@ int color_to_gd(gdImagePtr im, VALUE color);
|
|
|
17
17
|
void gd_define_image(VALUE mGD);
|
|
18
18
|
void gd_define_blit(VALUE cGDImage);
|
|
19
19
|
void gd_define_fill(VALUE cGDImage);
|
|
20
|
-
void gd_define_antialias(VALUE cGDImage);
|
|
21
20
|
|
|
22
21
|
void gd_define_pixel(VALUE cGDImage);
|
|
23
22
|
void gd_define_line(VALUE cGDImage);
|
data/ext/gd/text.c
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
#include "ruby_gd.h"
|
|
2
|
-
/*
|
|
3
|
-
- [ ] imagefontheight — Get font height
|
|
4
|
-
- [ ] imagefontwidth — Get font width
|
|
5
|
-
- [ ] imageftbbox — Give the bounding box of a text using fonts via freetype2
|
|
6
|
-
- [ ] imagefttext — Write text to the image using fonts using FreeType 2
|
|
7
|
-
*/
|
|
8
2
|
|
|
9
3
|
static VALUE gd_image_text(VALUE self, VALUE text, VALUE opts) {
|
|
10
4
|
gd_image_wrapper *wrap;
|
|
@@ -39,6 +33,109 @@ static VALUE gd_image_text(VALUE self, VALUE text, VALUE opts) {
|
|
|
39
33
|
return Qnil;
|
|
40
34
|
}
|
|
41
35
|
|
|
36
|
+
static VALUE gd_image_text_bbox(VALUE self, VALUE text, VALUE opts) {
|
|
37
|
+
gd_image_wrapper *wrap;
|
|
38
|
+
TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
|
|
39
|
+
|
|
40
|
+
VALUE fontV = rb_hash_aref(opts, ID2SYM(rb_intern("font")));
|
|
41
|
+
VALUE sizeV = rb_hash_aref(opts, ID2SYM(rb_intern("size")));
|
|
42
|
+
|
|
43
|
+
if (NIL_P(fontV) || NIL_P(sizeV))
|
|
44
|
+
rb_raise(rb_eArgError, "font and size are required");
|
|
45
|
+
|
|
46
|
+
VALUE angleV = rb_hash_aref(opts, ID2SYM(rb_intern("angle")));
|
|
47
|
+
double angle = NIL_P(angleV) ? 0.0 : NUM2DBL(angleV);
|
|
48
|
+
|
|
49
|
+
const char *font = StringValueCStr(fontV);
|
|
50
|
+
const char *str = StringValueCStr(text);
|
|
51
|
+
double size = NUM2DBL(sizeV);
|
|
52
|
+
|
|
53
|
+
int brect[8];
|
|
54
|
+
|
|
55
|
+
gdFTStringExtra extra;
|
|
56
|
+
memset(&extra, 0, sizeof(extra));
|
|
57
|
+
|
|
58
|
+
char *err = gdImageStringFTEx(
|
|
59
|
+
wrap->img,
|
|
60
|
+
brect,
|
|
61
|
+
0, /* no color, we don't draw */
|
|
62
|
+
font,
|
|
63
|
+
size,
|
|
64
|
+
angle,
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
str,
|
|
68
|
+
&extra
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
if (err) rb_raise(rb_eRuntimeError, "%s", err);
|
|
72
|
+
|
|
73
|
+
int w = brect[2] - brect[0];
|
|
74
|
+
int h = brect[1] - brect[7];
|
|
75
|
+
|
|
76
|
+
VALUE ary = rb_ary_new2(2);
|
|
77
|
+
rb_ary_push(ary, INT2NUM(w));
|
|
78
|
+
rb_ary_push(ary, INT2NUM(h));
|
|
79
|
+
return ary;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
static VALUE gd_image_text_ft(VALUE self, VALUE text, VALUE opts) {
|
|
84
|
+
gd_image_wrapper *wrap;
|
|
85
|
+
TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
|
|
86
|
+
|
|
87
|
+
VALUE xV = rb_hash_aref(opts, ID2SYM(rb_intern("x")));
|
|
88
|
+
VALUE yV = rb_hash_aref(opts, ID2SYM(rb_intern("y")));
|
|
89
|
+
VALUE sizeV = rb_hash_aref(opts, ID2SYM(rb_intern("size")));
|
|
90
|
+
VALUE colorV = rb_hash_aref(opts, ID2SYM(rb_intern("color")));
|
|
91
|
+
VALUE fontV = rb_hash_aref(opts, ID2SYM(rb_intern("font")));
|
|
92
|
+
|
|
93
|
+
if (NIL_P(xV)||NIL_P(yV)||NIL_P(sizeV)||NIL_P(colorV)||NIL_P(fontV))
|
|
94
|
+
rb_raise(rb_eArgError, "missing required options");
|
|
95
|
+
|
|
96
|
+
int x = NUM2INT(xV);
|
|
97
|
+
int y = NUM2INT(yV);
|
|
98
|
+
double size = NUM2DBL(sizeV);
|
|
99
|
+
const char *font = StringValueCStr(fontV);
|
|
100
|
+
const char *str = StringValueCStr(text);
|
|
101
|
+
|
|
102
|
+
VALUE angleV = rb_hash_aref(opts, ID2SYM(rb_intern("angle")));
|
|
103
|
+
double angle = NIL_P(angleV) ? 0.0 : NUM2DBL(angleV);
|
|
104
|
+
|
|
105
|
+
VALUE dpiV = rb_hash_aref(opts, ID2SYM(rb_intern("dpi")));
|
|
106
|
+
int dpi = NIL_P(dpiV) ? 96 : NUM2INT(dpiV);
|
|
107
|
+
//
|
|
108
|
+
VALUE lsV = rb_hash_aref(opts, ID2SYM(rb_intern("line_spacing")));
|
|
109
|
+
double ls = NIL_P(lsV) ? 1.0 : NUM2DBL(lsV);
|
|
110
|
+
|
|
111
|
+
int fg = color_to_gd(wrap->img, colorV);
|
|
112
|
+
|
|
113
|
+
gdFTStringExtra extra;
|
|
114
|
+
memset(&extra, 0, sizeof(extra));
|
|
115
|
+
extra.flags = gdFTEX_LINESPACE | gdFTEX_RESOLUTION;
|
|
116
|
+
extra.linespacing = ls;
|
|
117
|
+
extra.hdpi = dpi;
|
|
118
|
+
extra.vdpi = dpi;
|
|
119
|
+
|
|
120
|
+
char *err = gdImageStringFTEx(
|
|
121
|
+
wrap->img,
|
|
122
|
+
NULL,
|
|
123
|
+
fg,
|
|
124
|
+
font,
|
|
125
|
+
size,
|
|
126
|
+
angle,
|
|
127
|
+
x,
|
|
128
|
+
y,
|
|
129
|
+
str,
|
|
130
|
+
&extra
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
if (err) rb_raise(rb_eRuntimeError, "%s", err);
|
|
134
|
+
return Qnil;
|
|
135
|
+
}
|
|
136
|
+
|
|
42
137
|
void gd_define_text(VALUE cGDImage) {
|
|
43
138
|
rb_define_method(cGDImage, "text", gd_image_text, 2);
|
|
139
|
+
rb_define_method(cGDImage, "text_bbox", gd_image_text_bbox, 2);
|
|
140
|
+
rb_define_method(cGDImage, "text_ft", gd_image_text_ft, 2);
|
|
44
141
|
}
|
data/ext/gd/text.o
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-libgd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Germán Alberto Giménez Silva
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: High-performance native Ruby bindings to libgd for image generation,
|
|
14
14
|
drawing, filters, alpha blending, and transformations.
|