Module: Axon::JPEG

Defined in:
ext/axon/jpeg.c

Defined Under Namespace

Classes: Reader

Class Method Summary collapse

Class Method Details

.write(image_in, io_out[, options]) ⇒ Integer

Writes the given image image_in to io_out as compressed JPEG data. Returns the number of bytes written.

options may contain the following symbols:

* :bufsize - the size in bytes of the writes that will be made to
   +io_out+.
* :quality - the JPEG quality on a 0..100 scale.
* :exif - raw exif data that will be saved in the header.
* :icc_profile - raw icc profile that will be saved in the header.

Example:

image = Axon::Solid.new(200, 300)
io = File.open("test.jpg", "w")
Axon::JPEG.write(image, io)     #=> 1234

Returns:

  • (Integer)


369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'ext/axon/jpeg.c', line 369

static VALUE
write_jpeg(int argc, VALUE *argv, VALUE self)
{
    VALUE image_in, io_out, rb_bufsize, icc_profile, exif, quality, options;
    int bufsize;

    rb_scan_args(argc, argv, "21", &image_in, &io_out, &options);

    bufsize = WRITE_BUFSIZE;

    if (!NIL_P(options) && TYPE(options) == T_HASH) {
  rb_bufsize = rb_hash_aref(options, sym_bufsize);
  if (!NIL_P(rb_bufsize)) {
      bufsize = NUM2INT(rb_bufsize);
      if (bufsize < 1)
    rb_raise(rb_eRuntimeError, "Buffer size must be greater than zero");
  }

  icc_profile = rb_hash_aref(options, sym_icc_profile);
  exif = rb_hash_aref(options, sym_exif);
  quality = rb_hash_aref(options, sym_quality);
    } else {
  icc_profile = Qnil;
  exif = Qnil;
  quality = Qnil;
    }

    return write_jpeg2(image_in, io_out, bufsize, icc_profile, exif, quality);
}