2017-03-13 4 views
1

나는 지팡이-PY와 ImageMagick이를 사용하여 다음 명령을 다시 시도하고있어 사용하여이 명령을 실행할 수 있습니다 방법 :나는 지팡이-PY와 ImageMagick이

convert -density 500 hello_world.pdf -quality 100 -monochrome -enhance – morphology close diamond hello_world.jpg 

답변

1

당신은 MagickCore에서 방법을 결합해야하고, MagickWand 것 라이브러리. 커널 성능은 시스템마다 크게 다를 수 있으므로 큰 밀도의 이미지로 작업 할 때 '작업 취소됨'메시지를 누르면 놀라지 마십시오.

import ctypes 
from wand.api import libmagick, library 
from wand.image import Image 

""" 
Kernel info methods on MagickCore library. 
""" 
libmagick.AcquireKernelInfo.argtypes = (ctypes.c_char_p,) 
libmagick.AcquireKernelInfo.restype = ctypes.c_void_p 
libmagick.DestroyKernelInfo.argtypes = (ctypes.c_void_p,) 
libmagick.DestroyKernelInfo.restype = ctypes.c_void_p 

""" 
Morphology method on MagickWand library. 
""" 
library.MagickMorphologyImage.argtypes = (ctypes.c_void_p, # wand 
              ctypes.c_int,  # method 
              ctypes.c_long, # iterations 
              ctypes.c_void_p) # kernel 
""" 
Enhance method on MagickWand library. 
""" 
library.MagickEnhanceImage.argtypes = (ctypes.c_void_p,) # wand 

# convert -density 500 hello_world.pdf 
with Image(filename='pdf-sample.pdf', resolution=500) as img: 
    # -quality 100 
    img.compression_quality = 100 
    # -monochrome 
    img.quantize(2,  # Target colors 
       'gray', # Colorspace 
       1,  # Treedepth 
       False, # No Dither 
       False) # Quantization error 
    # -enhance 
    library.MagickEnhanceImage(img.wand) 
    # -morphology close diamond 
    p = ctypes.create_string_buffer(b'Diamond') 
    kernel = libmagick.AcquireKernelInfo(p) 
    CloseMorphology = 9 # See `morphology.h' 
    library.MagickMorphologyImage(img.wand, CloseMorphology, 1, kernel) 
    kernel = libmagick.DestroyKernelInfo(kernel) # Free memory 
    # hello_world.jpg 
    img.save(filename='hello_world.jpg') 
+0

코드 주셔서 감사합니다! 이 행에'ArgumentError : argument 1 : : 잘못된 유형'오류가 발생했습니다 :'kernel = libmagick.AcquireKernelInfo ('Diamond')', 저는 ImageMagick-6.9.8-Q8 버전을 사용하고 있습니다. 도움이된다면 원드 0.4.4. – billz

+0

흠. 'create_string_buffer'를 사용해보십시오. 나는이 모듈'C : \ Users \ xxxxx \ AppData \ Local \ Continuum \ Anaconda3 \ lib \ ctypes \ __ init__.py create_string_buffer (init, size)'에서 유사한 오류 :'TypeError : Diamond'를 업데이트 할 것이다 : at at – emcconville

+0

이 줄은'p = ctypes.create_string_buffer ('Diamond')'이다. 다시 한 번 도움을 주셔서 감사합니다! – billz