画像を取得して、imagemagick http://www.imagemagick.org/Usage/transform/#polaroidから次の効果を追加しようとしています。Python コードの例を検索しましたが、うまくいきませんでした。imagemagick (wand、pythonmagick など) を使用する必要はありません。これは、私が見つけた唯一の例です。リストされているようなコマンドラインの例を使用したくありません。私の写真ブースのpythonコードにそれを含めたいと思っています。
1 に答える
0
wandMagickPolaroidImage
では、C-API メソッド&を実装する必要があります。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 に答える