def tiled(self, size): size = Size.coerce(size) new = Image.new(size) # TODO this returns a bool? lib.TextureImage(new._stack, self._frame) magick_raise(self._frame.exception) return new
def translucent(self, value): if bool(value) == self.translucent: return if value: # Set the alpha channel lib.SetImageAlphaChannel(self._frame, lib.SetAlphaChannel) else: # Disable it lib.SetImageAlphaChannel(self._frame, lib.DeactivateAlphaChannel) magick_raise(self._frame.exception)
def new(cls, size, fill=None): """Create a new image (with one frame) of the given size.""" size = Size.coerce(size) image_info = blank_image_info() magick_pixel = blank_magick_pixel() if fill is None: # TODO need a way to explicitly create a certain color fill = RGBColor(0., 0., 0., 0.) fill._populate_magick_pixel(magick_pixel) ptr = lib.NewMagickImage(image_info, size.width, size.height, magick_pixel) magick_raise(ptr.exception) return cls(ptr)
def write(self, filename, format=None): if not self._frames: raise EmptyImageError with open(filename, "wb") as fh: image_info = blank_image_info() image_info.file = ffi.cast("FILE *", fh) # Force writing to a single file image_info.adjoin = lib.MagickTrue if format: # If the caller provided an explicit format, pass it along # Make sure not to overflow the char[] # TODO maybe just error out when this happens image_info.magick = format.encode('ascii')[:lib.MaxTextExtent] elif self._frames[0]._frame.magick[0] == b'\0': # Uhoh; no format provided and nothing given by caller raise MissingFormatError # TODO detect format from filename if explicitly asked to do so with self._link_frames(self._frames) as ptr: lib.WriteImage(image_info, ptr) magick_raise(ptr.exception)
def _fix_for_rgba_codec(self): # Older versions of ImageMagick spit out garbage for the alpha channel # when writing an alphaless image as "rgba". if not self._frame.matte: lib.SetImageAlphaChannel(self._frame, lib.OpaqueAlphaChannel) magick_raise(self._frame.exception)