Class: Rszr::Image
Defined Under Namespace
Modules: Transformations
Constant Summary
collapse
- GRAVITIES =
[true, :center, :n, :nw, :w, :sw, :s, :se, :e, :ne].freeze
Constants included
from Orientation
Orientation::ROTATIONS
Class Method Summary
collapse
Instance Method Summary
collapse
#blur, #blur!, #brighten, #brighten!, #contrast, #contrast!, #crop, #crop!, #filter, #flip, #flop, #gamma, #gamma!, #resize, #resize!, #rotate, #rotate!, #sharpen, #sharpen!, #turn, #turn!
included
Methods included from Buffered
included
Constructor Details
#initialize(rb_width, rb_height) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'ext/rszr/image.c', line 37
static VALUE rszr_image_initialize(VALUE self, VALUE rb_width, VALUE rb_height)
{
rszr_image_handle * handle;
Check_Type(rb_width, T_FIXNUM);
Check_Type(rb_height, T_FIXNUM);
Data_Get_Struct(self, rszr_image_handle, handle);
handle->image = imlib_create_image(FIX2INT(rb_width), FIX2INT(rb_height));
return self;
}
|
Class Method Details
.load(path, autorotate: Rszr.autorotate, **opts) ⇒ Object
Also known as:
open
11
12
13
14
15
16
17
|
# File 'lib/rszr/image.rb', line 11
def load(path, autorotate: Rszr.autorotate, **opts)
path = path.to_s
raise FileNotFound unless File.exist?(path)
image = _load(path)
autorotate(image, path) if autorotate
image
end
|
.load_data(data, autorotate: Rszr.autorotate, **opts) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/rszr/image.rb', line 20
def load_data(data, autorotate: Rszr.autorotate, **opts)
raise LoadError, 'Unknown format' unless format = identify(data)
with_tempfile(format, data) do |file|
load(file.path, autorotate: autorotate, **opts)
end
end
|
Instance Method Details
#[](x, y) ⇒ Object
43
44
45
46
47
|
# File 'lib/rszr/image.rb', line 43
def [](x, y)
if x >= 0 && x <= width - 1 && y >= 0 && y <= height - 1
Color::RGBA.new(*_pixel(x, y))
end
end
|
#dimensions ⇒ Object
29
30
31
|
# File 'lib/rszr/image.rb', line 29
def dimensions
[width, height]
end
|
#dup ⇒ Object
static VALUE rszr_image_get_quality(VALUE self) {
rszr_image_handle * handle;
int quality;
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
quality = imlib_image_get_attached_value("quality");
if (quality) {
return INT2NUM(quality);
} else {
return Qnil;
}
}
static VALUE rszr_image_set_quality(VALUE self, VALUE rb_quality) {
rszr_image_handle * handle;
int quality;
Check_Type(rb_quality, T_FIXNUM);
quality = FIX2INT(rb_quality);
if (quality <= 0) {
rb_raise(rb_eArgError, "quality must be >= 0");
return Qnil;
}
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
imlib_image_attach_data_value("quality", NULL, quality, NULL);
return INT2NUM(quality);
}
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'ext/rszr/image.c', line 208
static VALUE rszr_image_dup(VALUE self)
{
rszr_image_handle * handle;
rszr_image_handle * cloned_handle;
Imlib_Image cloned_image;
VALUE oClonedImage;
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
cloned_image = imlib_clone_image();
if (!cloned_image) {
rb_raise(eRszrTransformationError, "error cloning image");
return Qnil;
}
oClonedImage = rszr_image_s_allocate(cImage);
Data_Get_Struct(oClonedImage, rszr_image_handle, cloned_handle);
cloned_handle->image = cloned_image;
return oClonedImage;
}
|
#filter!(rb_filter_expr) ⇒ Object
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# File 'ext/rszr/image.c', line 308
static VALUE rszr_image_filter_bang(VALUE self, VALUE rb_filter_expr)
{
rszr_image_handle * handle;
char * filter_expr;
filter_expr = StringValueCStr(rb_filter_expr);
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
imlib_apply_filter(filter_expr);
return self;
}
|
#flip! ⇒ Object
259
260
261
262
263
264
265
266
267
268
269
|
# File 'ext/rszr/image.c', line 259
static VALUE rszr_image_flip_bang(VALUE self)
{
rszr_image_handle * handle;
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
imlib_image_flip_vertical();
return self;
}
|
#flop! ⇒ Object
246
247
248
249
250
251
252
253
254
255
256
|
# File 'ext/rszr/image.c', line 246
static VALUE rszr_image_flop_bang(VALUE self)
{
rszr_image_handle * handle;
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
imlib_image_flip_horizontal();
return self;
}
|
33
34
35
36
|
# File 'lib/rszr/image.rb', line 33
def format
fmt = _format
fmt == 'jpg' ? 'jpeg' : fmt
end
|
38
39
40
41
|
# File 'lib/rszr/image.rb', line 38
def format=(fmt)
fmt = fmt.to_s if fmt.is_a?(Symbol)
self._format = fmt
end
|
#height ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'ext/rszr/image.c', line 130
static VALUE rszr_image_height(VALUE self)
{
rszr_image_handle * handle;
int height;
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
height = imlib_image_get_height();
return INT2NUM(height);
}
|
#inspect ⇒ Object
49
50
51
52
53
|
# File 'lib/rszr/image.rb', line 49
def inspect
fmt = format
fmt = " #{fmt.upcase}" if fmt
"#<#{self.class.name}:0x#{object_id.to_s(16)} #{width}x#{height}#{fmt}>"
end
|
#save(path, format: nil, quality: nil) ⇒ Object
151
152
153
154
155
156
|
# File 'lib/rszr/image.rb', line 151
def save(path, format: nil, quality: nil)
format ||= format_from_filename(path) || self.format || 'jpg'
raise ArgumentError, "invalid quality #{quality.inspect}" if quality && !(0..100).cover?(quality)
ensure_path_is_writable(path)
_save(path.to_s, format.to_s, quality)
end
|
#save_data(format: nil, quality: nil) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/rszr/image.rb', line 158
def save_data(format: nil, quality: nil)
format ||= self.format || 'jpg'
with_tempfile(format) do |file|
save(file.path, format: format, quality: quality)
file.rewind
file.read
end
end
|
#width ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'ext/rszr/image.c', line 116
static VALUE rszr_image_width(VALUE self)
{
rszr_image_handle * handle;
int width;
Data_Get_Struct(self, rszr_image_handle, handle);
imlib_context_set_image(handle->image);
width = imlib_image_get_width();
return INT2NUM(width);
}
|