Exemplo n.º 1
0
 def func(self, *args):
     args = [self] + list(args)
     res = fun(*args)
     if not res:
         if self.exception:
             raise ImageMagickException(self.exception)
     return bool(res)
Exemplo n.º 2
0
 def copyPixels(self, source, sx, sy, w, h, tx, ty):
     exc = ExceptionInfo()
     dest = lib.GetAuthenticPixels(self, tx, ty, w, h, exc)
     if not dest:
         raise ImageMagickException(exc)
     src = lib.GetAuthenticPixels(source, sx, sy, w, h, exc)
     if not src:
         raise ImageMagickException(exc)
     artype = ctypes.POINTER(PixelPacket * (w * h))
     artype1 = PixelPacket * (w * h)
     dest = ctypes.cast(dest, artype)
     src = ctypes.cast(src, artype)
     for i in range(w * h):
         dest[0][i] = src[0][i]
     if not lib.SyncAuthenticPixels(self, exc):
         raise ImageMagickException(exc)
Exemplo n.º 3
0
 def func(self, *args):
     exc = ExceptionInfo()
     args = [self] + list(args) + [exc]
     res = fun(*args)
     if not res:
         raise ImageMagickException(exc)
     return Image(res)
Exemplo n.º 4
0
 def compare(self, other, metric):
     dbl = (ctypes.c_double * 1)()
     exp = ExceptionInfo()
     img = CompareImageChannels(self, other, ChannelType.All, metric, dbl,
                                exp)
     if not img:
         raise ImageMagickException(exp)
     return (dbl[0], Image(img))
Exemplo n.º 5
0
 def write(self, file):
     if isinstance(file, str):
         self.images[0].filename = file
         if not lib.WriteImage(self.info, self.images[0]):
             raise ImageMagickException(self.images[0].exception)
         return True
     else:
         raise NotImplementedError
Exemplo n.º 6
0
 def write(self, file):
     if isinstance(file, str):
         inf = ImageInfo()
         self.filename = file
         if not lib.WriteImage(inf, self):
             raise ImageMagickException(self.exception)
         return True
     else:
         raise NotImplementedError
Exemplo n.º 7
0
 def create(C, width, height, color):
     inf = ImageInfo()
     res = lib.NewMagickImage(inf, width, height, ctypes.byref(color))
     if not res:
         raise ImageMagickException(inf.exception)
     im = C(res)
     im.setColorspace(ColorspaceType.RGB.value)
     im.setBackgroundColor(color)
     return im
Exemplo n.º 8
0
 def __enter__(self):
     exc = ExceptionInfo()
     px = lib.GetAuthenticPixels(self.im, self.x, self.y, self.w, self.h,
                                 exc)
     if not px:
         raise ImageMagickException(exc)
     self.px = ctypes.cast(px,
                           ctypes.POINTER(PixelPacket * (self.w * self.h)))
     return self
Exemplo n.º 9
0
 def draw(self, string):
     inf = DrawInfo()
     data = string.encode('utf-8')
     buf = ctypes.c_buffer(data)
     inf.primitive = ctypes.cast(buf, ctypes.c_char_p)
     try:
         if not lib.DrawImage(self.value, inf):
             raise ImageMagickException(self.exception)
     finally:
         inf.primitive = 0
Exemplo n.º 10
0
 def ping(C, file):
     if isinstance(file, str):
         inf = ImageInfo()
         inf.filename = file
         exinfo = ExceptionInfo()
         res = lib.PingImage(inf, exinfo)
         if not res:
             raise ImageMagickException(exinfo)
         return C(res)
     else:
         raise NotImplementedError
Exemplo n.º 11
0
 def tile(C, file, width, height):
     if isinstance(file, str):
         inf = ImageInfo()
         file = 'tile:' + file
         inf.size = "%dx%d" % (width, height)
         inf.filename = file
         try:
             exinfo = ExceptionInfo()
             res = lib.ReadImage(inf, exinfo)
             if not res:
                 raise ImageMagickException(exinfo)
             return C(res)
         finally:
             inf.size = 0
             inf.file = 0
     else:
         raise NotImplementedError
Exemplo n.º 12
0
 def copy(self):
     exc = ExceptionInfo()
     res = lib.CloneImage(self, 0, 0, True, exc)
     if not res:
         raise ImageMagickException(exc)
     return Image(res)
Exemplo n.º 13
0
 def display(self):
     inf = ImageInfo()
     res = lib.DisplayImages(inf, self)
     if not res:
         raise ImageMagickException(self.exception)