我正在尝试拍摄图像并从 imagemagick http://www.imagemagick.org/Usage/transform/#polaroid添加以下效果。我搜索了 Python 代码示例并没有成功。我不需要使用 imagemagick(wand, pythonmagick, etc.) 这只是我能找到的唯一例子。我不想使用列出的命令行示例。我希望能够将它包含在我的照相亭 python 代码中。
问问题
679 次
1 回答
0
使用wand,您将需要实现 C-API 方法MagickPolaroidImage
&MagickSetImageBorderColor
import ctypes
from wand.api import library
from wand.color import Color
from wand.drawing import Drawing
from wand.image import Image
# Tell Python about C library
library.MagickPolaroidImage.argtypes = (ctypes.c_void_p, # MagickWand *
ctypes.c_void_p, # DrawingWand *
ctypes.c_double) # Double
library.MagickSetImageBorderColor.argtypes = (ctypes.c_void_p, # MagickWand *
ctypes.c_void_p) # PixelWand *
# Define FX method. See MagickPolaroidImage in wand/magick-image.c
def polaroid(wand, context, angle=0.0):
if not isinstance(wand, Image):
raise TypeError('wand must be instance of Image, not ' + repr(wand))
if not isinstance(context, Drawing):
raise TypeError('context must be instance of Drawing, not ' + repr(context))
library.MagickPolaroidImage(wand.wand,
context.resource,
angle)
# Example usage
with Image(filename='rose:') as image:
# Assigne border color
with Color('white') as white:
library.MagickSetImageBorderColor(image.wand, white.resource)
with Drawing() as annotation:
# ... Optional caption text here ...
polaroid(image, annotation)
image.save(filename='/tmp/out.png')
于 2016-08-15T13:15:06.520 回答