Module: AsyncVips

Defined in:
lib/async_vips/version.rb,
ext/async_vips.c

Defined Under Namespace

Classes: Error, Image

Constant Summary collapse

VERSION =
"1.2.2"
LIB_VERSION =
av_version_string()

Class Method Summary collapse

Class Method Details

.debug_infoObject

Print internal debugging information from VIPS, including memory allocation information.



22
23
24
25
26
# File 'ext/async_vips.c', line 22

static VALUE av_debug_info(VALUE self)
{
    vips_object_print_all();
    return Qnil;
}

.info(*args) ⇒ Object

Returns image information: width, height, file size



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'ext/info.c', line 10

static VALUE av_info(int argc, VALUE *argv, VALUE self)
{
    rb_need_block();
    VALUE proc = rb_block_proc();

    VALUE rest;
    rb_scan_args(argc, argv, "*", &rest);

    VALUE params = rb_ary_pop(rest);
    VALUE tmp = rb_check_hash_type(params);
    if (NIL_P(tmp))
        rb_raise(rb_eArgError, "No info parameters specified");

    // Parse options
    VALUE load = rb_hash_aref(params, ID2SYM(av_i_id_load));
    if(NIL_P(load))
        rb_raise(rb_eArgError, "No image source specified: info(:load => 'image.jpg')");

    transform_data_t* tdata = av_make_transform_data_src(StringValuePtr(load));
    tdata->proc = proc;

    rb_gc_register_address(&tdata->proc);

    av_enqueue_task(av_build_image_thread_func, tdata);

    return self;
}

.set_cache(val) ⇒ Object

Set the max number of operations to keep in cache.



29
30
31
32
33
# File 'ext/async_vips.c', line 29

static VALUE av_set_cache(VALUE self, VALUE val)
{
    vips_cache_set_max(NUM2INT(val));
    return Qnil;
}

.transform(*args) ⇒ Object

Image transformation



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'ext/transform.c', line 334

static VALUE av_transform(int argc, VALUE *argv, VALUE self)
{
    rb_need_block();
    VALUE proc = rb_block_proc();

    VALUE rest;
    rb_scan_args(argc, argv, "*", &rest);

    VALUE params = rb_ary_pop(rest);
    VALUE tmp = rb_check_hash_type(params);
    if (NIL_P(tmp))
        rb_raise(rb_eArgError, "No transformation parameters specified");

    // Parse options
    VALUE load = rb_hash_aref(params, ID2SYM(av_t_id_load));
    if(NIL_P(load))
        rb_raise(rb_eArgError, "No image source specified: transform(:load => 'image.jpg')");

    VALUE save = rb_hash_aref(params, ID2SYM(av_t_id_save));
    if(NIL_P(save))
        rb_raise(rb_eArgError, "No image destination specified: transform(:save => 'output.jpg')");

    VALUE scale_x = rb_hash_aref(params, ID2SYM(av_t_id_scale_x));
    VALUE scale_y = rb_hash_aref(params, ID2SYM(av_t_id_scale_y));

    if(NIL_P(scale_x) && NIL_P(scale_y))
        rb_raise(rb_eArgError, "No scale width or height specified of the source image: transform(:scale_x => 800, :scale_y => 600)");

    if(NIL_P(scale_y))
        scale_y = scale_x;

    if(NIL_P(scale_x))
        scale_x = scale_y;

    VALUE natural_orient_flag = rb_hash_aref(params, ID2SYM(av_t_id_natural_orientation));
    if(!NIL_P(natural_orient_flag) &&
       (TYPE(natural_orient_flag) != T_TRUE) && (TYPE(natural_orient_flag) != T_FALSE))
        rb_raise(rb_eArgError, "Invalid natural orientation: transform(:natural_orientation => true|false)");

    transform_data_t* tdata = av_make_transform_data(StringValuePtr(load), StringValuePtr(save));
    tdata->target_width = NUM2INT(scale_x);
    tdata->target_height = NUM2INT(scale_y);
    tdata->natural_orientation = (TYPE(natural_orient_flag) == T_TRUE ? 1 : 0);
    tdata->proc = proc;

    rb_gc_register_address(&tdata->proc);

    av_enqueue_task(av_build_image_thread_func, tdata);

    return self;
}