1

이미지를 가져 와서 imagemagick http://www.imagemagick.org/Usage/transform/#polaroid에서 다음 효과를 추가하려고합니다. 파이썬 코드 예제를 검색했지만 성공하지 못했습니다. imagemagick (지팡이, pythonmagick 등)을 사용할 필요가 없습니다. 이것은 제가 발견 할 수있는 유일한 예일뿐입니다. 나열된 명령 줄 예제를 사용하고 싶지 않습니다. 내 사진 부스 파이썬 코드에 포함시킬 수 있기를 바랍니다. 이미지가 파이썬으로 된 폴라로이드 효과

+0

왜 서브 프로세스/커맨드 라인 기반의 접근 방식을 사용하지 않으 MagickPolaroidImage를 구현해야합니다? 이것은 가장 쉽고 강력합니다 (모든 옵션에 대한 액세스). 완드가 그것을 지원하지 않는 것 같아요 (폴라로이드), Pythonmagick은 제 시스템에서 컴파일조차하지 않습니다. 그리고 나는이 라이브러리들이 얼마나 얽혀 있는지 (모든 것을 지원하는 것) 모르 십니다. cli 기반 접근법은 python의 [tempfile] (https://docs.python.org/3.5/library/tempfile.html)을 사용하면 상당히 깨끗합니다. – sascha

+0

저는 파이썬의 tempfile 모듈에 익숙하지 않습니다. 파이썬 스크립트 내에서 폴라로이드 명령을 깔끔하게 실행할 수있는 예가 있습니까? –

답변

0

, 당신은 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') 

Polaroid effect with Python & wand

+0

그림자를 조작 할 수있는 방법이 있습니까? 더 큰 이미지의 그림자는별로 매력적이지 않습니다! –