def process_image(raw_content): import _libimg alpha = None _libimg.init_magick() wand = _libimg.new_image() _libimg.load_image_blob(wand, raw_content) image_type = _libimg.get_image_type(wand) if image_type in ALPHA_TYPES: alpha_wand = _libimg.clone_image(wand) _libimg.remove_alpha_channel(wand) _libimg.set_image_format(alpha_wand, 'png') _libimg.set_image_type(alpha_wand, RGBA_TYPE) alpha = StringIO(_libimg.get_image_blob(alpha_wand)) alpha.seek(0) if image_type in CMYK_TYPES: _libimg.set_image_format(wand, 'tiff') _libimg.set_image_type(wand, CMYK_TYPE) else: _libimg.set_image_format(wand, 'png') base = StringIO(_libimg.get_image_blob(wand)) base.seek(0) _libimg.terminate_magick() return base, alpha
def process_image(raw_content): import _libimg LOG.debug('MagickWand processing started') alpha = None _libimg.init_magick() wand = _libimg.new_image() _libimg.load_image_blob(wand, raw_content) if _libimg.get_number_images(wand) > 1: LOG.debug('Wand merging.') wand = _libimg.merge_layers(wand) image_type = _libimg.get_image_type(wand) LOG.debug('Wand image type: %s', image_type) if image_type in ALPHA_TYPES: alpha_wand = _libimg.clone_image(wand) _libimg.remove_alpha_channel(wand) _libimg.set_image_format(alpha_wand, 'png') _libimg.set_image_type(alpha_wand, RGBA_TYPE) alpha = StringIO(_libimg.get_image_blob(alpha_wand)) alpha.seek(0) if image_type in CMYK_TYPES: _libimg.set_image_format(wand, 'tiff') _libimg.set_image_type(wand, CMYK_TYPE) else: _libimg.set_image_format(wand, 'png') base = StringIO(_libimg.get_image_blob(wand)) base.seek(0) _libimg.terminate_magick() return base, alpha
def process_pattern(raw_content): import _libimg _libimg.init_magick() wand = _libimg.new_image() _libimg.load_image_blob(wand, raw_content) image_type = _libimg.get_image_type(wand) _libimg.set_image_format(wand, 'tiff') base = StringIO(_libimg.get_image_blob(wand)) base.seek(0) _libimg.terminate_magick() return base, image_type in DUOTONES