简体   繁体   中英

trying to watermarking an image with MagickWand method using python

I have a problem integrating Python and C through ctypes .

The problem is in the method MagicSteganoImage , this method returns 0 therefore can not write the final result.

Someone help me? thanks to all.

path="path/photo.png"
markpath="path/mark.png"
libwand=CDLL("libMagickWand-6.Q16.so.2")
libwand.MagickWandGenesis()
mw=libwand.NewMagickWand()
libwand.MagickReadImage(mw,path)
mark=libwand.NewMagickWand()
libwand.MagickReadImage(mark,markpath)
result=libwand.NewMagickWand()
result = libwand.MagickSteganoImage(mw,mark,0)
libwand.MagickWriteImage(result,dest)

You must tell python how to interact with C API.

from ctypes import *
libwand=CDLL("libMagickWand-6.Q16.so.2")
# Communicated how python should handle ctypes
libwand.NewMagickWand.restype = c_void_p
libwand.MagickReadImage.argtypes = (c_void_p, c_char_p)
libwand.MagickSteganoImage.argtypes = (c_void_p, c_void_p, c_int)
libwand.MagickSteganoImage.restype = c_void_p
libwand.MagickWriteImage.argtypes = (c_void_p, c_char_p)
# ... work

As well as build out error handling to interact with C-API exceptions.

For additional help, you can evaluate the source code of .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM