I'm trying to take an image and add the following effect from imagemagick http://www.imagemagick.org/Usage/transform/#polaroid. I've searched for Python code examples and have been unsuccessful. I don't need to use imagemagick(wand, pythonmagick, etc.) this was just the only example of this I could find. I don't want to use the command line example like listed. I would love to be able to include it in my photo booth python code.
Asked
Active
Viewed 908 times
1
-
Why don't you want to use a subprocess/commandline-based approach? This one is the easiest, and most powerful (access to all options). Wand seems not supporting it (polaroid), Pythonmagick doesn't even compile on my system and i don't know how deep these libs are intertwined (supporting everything). A cli-based approach could be quite clean with the use of python's [tempfile](https://docs.python.org/3.5/library/tempfile.html). – sascha Aug 12 '16 at 23:30
-
I'm not familiar with python's tempfile module. Do you have an example that could run the polaroid command within python script cleanly? – Kyle Richards Aug 13 '16 at 18:59
1 Answers
0
With wand, you will need to implement the C-API methods 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')

emcconville
- 23,800
- 4
- 50
- 66
-
Is there a way to manipulate the shadow? With bigger images, the shadow doesn't look very appealing! – Kyle Richards Aug 19 '16 at 22:42