def get_blob(image, format, compression, # @ReservedAssignment quality): with state(image, compression=compression, compression_quality=quality): format = format.upper() # @ReservedAssignment old_format = c_call('magick', 'get_format', image) c_call('magick', 'set_format', image, format) size = c_size_t() result = c_call(image, ('get', 'blob'), byref(size)) #from nose.tools import set_trace; set_trace() blob = string_at(result, size.value) c_call('magick_', 'relinquish_memory', result) c_call('magick', 'set_format', image, old_format) return blob
def handle_result(result, restype, args, argtypes): if restype == c_char_p: result = native_str(result) if restype in (c_uint, c_ssize_t, c_size_t): result = int(result) elif restype == enum and not jython: result = result.value elif restype == MagickBoolean and not result: exc_type = ExceptionType() if argtypes[0] == MagickWand_p: klass = 'magick' elif argtypes[0] == PixelWand_p: klass = 'pixel' description = c_call(klass, 'get_exception', args[0], byref(exc_type)) try: raise PystaciaException(native_str(string_at(description))) finally: c_call('magick_', 'relinquish_memory', description) return result
def get_blob( image, format, compression, # @ReservedAssignment quality): with state(image, compression=compression, compression_quality=quality): format = format.upper() # @ReservedAssignment old_format = c_call('magick', 'get_format', image) c_call('magick', 'set_format', image, format) size = c_size_t() result = c_call(image, ('get', 'blob'), byref(size)) #from nose.tools import set_trace; set_trace() blob = string_at(result, size.value) c_call('magick_', 'relinquish_memory', result) c_call('magick', 'set_format', image, old_format) return blob