Method: Magick::Image.read_inline
- Defined in:
- ext/RMagick/rmimage.c
.read_inline(content) ⇒ Object
Read a Base64-encoded image.
Ruby usage:
- @verbatim Image.read_inline(content) @endverbatim
Notes:
- This is similar to, but not the same as ReadInlineImage. ReadInlineImage
requires a comma preceeding the image data. This method allows but does
not require a comma.
10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 |
# File 'ext/RMagick/rmimage.c', line 10727
VALUE
Image_read_inline(VALUE self, VALUE content)
{
volatile VALUE info_obj;
Image *images;
ImageInfo *info;
char *image_data;
long x, image_data_l;
unsigned char *blob;
size_t blob_l;
ExceptionInfo exception;
self = self; // defeat gcc message
image_data = rm_str2cstr(content, &image_data_l);
// Search for a comma. If found, we'll set the start of the
// image data just following the comma. Otherwise we'll assume
// the image data starts with the first byte.
for (x = 0; x < image_data_l; x++)
{
if (image_data[x] == ',')
{
break;
}
}
if (x < image_data_l)
{
image_data += x + 1;
}
blob = Base64Decode(image_data, &blob_l);
if (blob_l == 0)
{
rb_raise(rb_eArgError, "can't decode image");
}
GetExceptionInfo(&exception);
// Create a new Info structure for this read. About the
// only useful attribute that can be set is `format'.
info_obj = rm_info_new();
Data_Get_Struct(info_obj, Info, info);
images = BlobToImage(info, blob, blob_l, &exception);
magick_free((void *)blob);
rm_check_exception(&exception, images, DestroyOnError);
(void) DestroyExceptionInfo(&exception);
rm_set_user_artifact(images, info);
return array_from_images(images);
}
|