Method: Magick::Image.read_inline
- Defined in:
- ext/RMagick/rmimage.cpp
.read_inline(content) {|info| ... } ⇒ Array<Magick::Image>
Read a Base64-encoded image.
11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 |
# File 'ext/RMagick/rmimage.cpp', line 11699
VALUE
Image_read_inline(VALUE self ATTRIBUTE_UNUSED, VALUE content)
{
VALUE info_obj;
Image *images;
ImageInfo *info;
char *image_data;
size_t x, image_data_l;
unsigned char *blob;
size_t blob_l;
ExceptionInfo *exception;
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;
}
GVL_STRUCT_TYPE(Base64Decode) args_Base64Decode = { image_data, &blob_l };
blob = (unsigned char *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(Base64Decode), &args_Base64Decode);
if (blob_l == 0)
{
rb_raise(rb_eArgError, "can't decode image");
}
exception = AcquireExceptionInfo();
// Create a new Info structure for this read. About the
// only useful attribute that can be set is `format'.
info_obj = rm_info_new();
TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info);
GVL_STRUCT_TYPE(BlobToImage) args_BlobToImage = { info, blob, blob_l, exception };
images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args_BlobToImage);
magick_free((void *)blob);
rm_check_exception(exception, images, DestroyOnError);
DestroyExceptionInfo(exception);
rm_set_user_artifact(images, info);
rm_sync_image_options(images, info);
RB_GC_GUARD(info_obj);
return array_from_images(images);
}
|