繁体   English   中英

尝试使用python使用MagickWand方法对图像加水印

[英]trying to watermarking an image with MagickWand method using python

我在通过ctypes集成Python和C时遇到问题。

问题出在方法MagicSteganoImage中,该方法返回0,因此无法写入最终结果。

谁来帮帮我? 谢谢大家。

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)

必须告诉python如何与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

以及建立错误处理以与C-API异常进行交互。

要获得更多帮助,您可以评估源代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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