EzDevInfo.com

wand

The ctypes-based simple ImageMagick binding for Python Wand — Wand 0.4.1

How to threshold an image using wand in python

using imagemagick I can threshold an image and specify a percentage.

convert one.png -threshold 60% two.png

How can I do the same using wand in python?


Source: (StackOverflow)

Python binding to ImageMagick

I am looking for a good Python binding to ImageMagick, but there seem a lot of bindings already. I am not sure that which of these is the right tool for my job. Can you guys recommend me one?

Here is the list of my requirements and preferences (in order of importance):

  1. Must be available on PyPI (to simplify our deployment)
  2. Prefer ctypes over C API extension — we will go PyPy soon
  3. Pythonic API design and naming conventions
  4. Good documentation (especially API references)

Source: (StackOverflow)

Advertisements

How to install python imagemagick at windows 7. I followed these instruction

To install python IMagick binding wand api on windows 64 bit (python 2.6)

This is what I did:

  1. downloaded and installed ImageMagick-6.5.8-7-Q16-windows-dll.exe

  2. downloaded wand module from http://pypi.python.org/pypi/Wand

  3. after that i ran python setup.py install from wand directory,

  4. then i executed step6. but i got the import error: magickband librarry not found

  5. downloaded magickwand' module and executed 'python setup.py install' from magickwand directory.

  6. then agian i tried this code

    from wand.image import Image
    from wand.display import display
    
    with Image(filename='mona-lisa.png') as img:
        print img.size
        for r in 1, 2, 3:
            with img.clone() as i:
                i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25))
                i.rotate(90 * r)
                i.save(filename='mona-lisa-{0}.png'.format(r))
                display(i)
    
  7. but thereafter again i am getting the same import error magickband library not found i am fed up with this coz i have done with all the installation. but not able to execute the code. coz everytime i am getting magickband libraray..import error.


Source: (StackOverflow)

no decode delegate for this image format `PNG'

I'm writing a django/python application and I need to convert PDF files uploaded by the user to JPEGs (files are scans)

I'm trying to use wand, with an ImageMagick backend (on OSX) and I keep getting the following error:

MissingDelegateError at /user_docs/upload/certificate/
no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/501

My current test code is as simple as:

with wandImage(filename='/Users/username/Pictures/telechargement.pdf') as img:
    img.format = 'jpeg'
    img.save(filename='/Users/username/Pictures/bzzz.jpeg')

Some information:

  1. The file exists (I verify with os.path.exists)
  2. I can convert the file from PDF to JPG on the command line using convert
  3. I tried to set DYLD_LIBRARY_PATH to include the ImageMagick lib directory
  4. identify -list configure | grep DELEGATES returns

DELEGATES bzlib fftw fontconfig freetype gs jpeg jng lcms2 lzma mpeg png tiff x11 xml zlib

Anyone has an idea?

Thanks


Source: (StackOverflow)

How to convert this command to a python code using Wand & ImageMagick

I want to convert an image so I can read it better using pyocr & tesseract. The Command line I want to convert to python is :

convert pic.png -background white -flatten -resize 300% pic_2.png

Using python Wand I managed to resize it but I don't know how to do the flattend and the white background My try :

from wand.image import Image
with Image(filename='pic.png') as image:
    image.resize(270, 33)  #Can I use 300% directly ?
    image.save(filename='pic2.png')

Please help
Edit, Here is the image to make tests on : enter image description here


Source: (StackOverflow)

Compositing two images with python wand

I need to use python wand (image-magick bindings for python) to create a composite image, but I'm having some trouble figuring out how to do anything other than simply copy pasting the foreground image into the background image. What I want is, given I have two images like:

foreground

and

enter image description here

both jpegs, I want to remove the white background of the cat and then paste it on the room. Answers for other python image modules, like PIL, are also fine, I just need something to automatize the composition process. Thanks in advance.


Source: (StackOverflow)

Python Wand generates lots of temporary files

We use Python Wand under Celery to process a lot of pictures. On some of our servers, our treatment sometimes leaves a lot of temporary files behind, e.g.:

$ ls -lh /tmp/ -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:35 magick-y1yKKiVZ -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:41 magick-Y22P6McK -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:37 magick-YaaSIYrk -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:39 magick-YEkn4H15 -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:39 magick-yf2Vrfwi -rw------- 1 ubuntu ubuntu 1.9M Apr 1 04:38 magick-YIYTaArn -rw------- 1 ubuntu ubuntu 199K Apr 1 04:43 magick-YLM5wYm9 -rw------- 1 ubuntu ubuntu 199K Apr 1 04:43 magick-YLo5SeVp [...]

Is there a way to make Wand clean up after it worked on some file? If it's the expected behavior, is there a way to debug this and know which image created which temp file, by putting a log statement for example?

Thanks


Source: (StackOverflow)

Get all pixels of an Image [Wand]

I am using the Wand Python Library, and trying to solve the Python Challenge, and my current problem asks me to get all even/odd pixels.

This is, obviously, a very simple task. However, I found the Wand library quite slow in loading pixels/copying pixels (Maybe it's because I also change fill_color to the color of the pixel for each?), and I was wondering if I could just load them all in at once.

My current solution to loading all pixels is something like this:

from wand.image import Image
img = Image(filename="5808.jpg")
pixels = []
for x in range(img.width+1):
    for y in range(img.height+1):
        pixels.append(img[x, y])

print(pixels)

I'd prefer something like this:

from wand.image import Image
img = Image(filename="5808.jpg")
print(img.pixels)

Is there anything akin to that? Thanks in advance.


Source: (StackOverflow)

Wand turns transparent background to black

I am trying to grayscale with pyhton using Wand, but when I do

from wand.image import Image
with Image(filename='image.png') as img:
    img.type = 'grayscale'
    img.save(filename='image_gray.png')

it turns the transparent background into black. If I use one with white background it works. What do I do wrong. And also as grayscaling is

Y = 0.2126 * RED + 0.7152 * GREEN + 0.0722 * BLUE

Where can I do that manually in Wand, say if I want to change the values a bit. I looked in the documentation and in various forums but I couldn't find any answer, only stuff for photoshop.

Thanks!


Source: (StackOverflow)

Wand Python multi-size icon

i'm trying to use Wand to create a multi-size ico, but i don't find anything talking about that, only normal conversion, to ico... i've found "Sequences":

https://wand.readthedocs.org/en/latest/roadmap.html

and sequences look like what i need, but i only see samples trying to read the multiple images, but not how to create, am i missing something? or is not possible?

or is it possible to do using PIL/PILLOW?


Source: (StackOverflow)

Handling files in Django

I'm using ImageMagick and the binding wand to generate thumbnails for uploaded images in Django. I can generate the thumbnail fine, but I'm uncertain about how to go about passing the image object from ImageMagick back into the Django model. So I have a simplified model as below:

from wand import Image

class Attachment(models.Model):
    attachment = models.FileField(upload_to="some_path")
    thumbnail = models.ImageField(upload_to="other_path")

    def generate_thumb(self):
        with Image(file=self.attachment) as wand:
            thumb = wand.resize(width=50, height=50)
            thumb.save(file=self.thumbnail)

This generates an error at the last line of ValueError: The 'thumbnail' attribute has no file associated with it. Is there a simple way to get a file object out of wand and into django without too much silliness?

Thanks.


Source: (StackOverflow)

Writing animated gif using Wand and ImageMagick

I'm having trouble figuring out how to write a basic sequence to an animated gif using Wand the ImageMagick binding.

The basic convert ImageMagick commands I'm looking to reproduce in python:

convert -delay 50  -size 500x500 xc:SkyBlue \
      -page +5+10  /test/wizard.gif  \
      -page +62+50  test/wizard2.gif  \
      -loop 0  animation.gif

Source: (StackOverflow)

advanced text formatting with wand (magickwand)

While creating images with formatted annotations i have found image magick ability to render html like formatted text (pango http://www.imagemagick.org/Usage/text/#pango ).

Further investigation showed that there is no pango functionality implemented in wand, but that is easy to implement if magickwand has this ability as wand just uses wraps it.

So the question is: how to use pango with magickwand if it's possible Or is there any other way to render formatted text (for example different colors and font weights of some words in the middle of text) without calculating positions and rendering all different formats separately?


Source: (StackOverflow)

Performance of python subprocess vs Wand?

I'm looking for a compute- and memory- efficient way to use ImageMagick in a Python program to retrieve the dimensions of batches of photos.

I first used the current favorite ImageMagick-Python package, Wand. I tried it and it felt slow. So I rigged up a test of it vs simply exec-ing ImageMagick using subprocess.check_output(). Subprocess was more than 10 TIMES faster.

My question: is that other people's experience? Is there a way to use Wand faster?

Wand took 1.2 seconds:

1.jpg: 3264x2448
2.jpg: 1600x1200
3.jpg: 1700x1101
4.jpg: 1600x1200
5.jpg: 3648x2736
6.jpg: 2789x1980
7.jpg: 2400x1600
8.jpg: 3648x2736
processed 8 files in 1.236s

Subprocess only took 0.1 seconds to retrieve the same files:

1.jpg: 3264x2448
2.jpg: 1600x1200
3.jpg: 1700x1101
4.jpg: 1600x1200
5.jpg: 3648x2736
6.jpg: 2789x1980
7.jpg: 2400x1600
8.jpg: 3648x2736
processed 8 files in 0.102s

The Wand code:

for filename in files:
  with wand.image.Image(filename=filename) as img: return img.width, img.height

The subprocess code:

subprocess.check_output(['identify', '-format', '%f:%w:%h\\n', 'path/to/imgs/*.jpg'])
# parse output by splitting each line on the ':'

I realize it's not apples to apples because I'm invoking ImageMagick once per file in Wand. However, I don't see any batch option in Wand, so I believe this is the best Wand can do for my scenario.

Thanks!


Source: (StackOverflow)

wand-py + ImageMagick scaling issue

I'm using wand-py (0.3.3) and ImageMagick(versions below) in an application to customize designs from source SVGs. I'm currently running into an issue with different versions of ImageMagick returning rather different results, and I'm hoping somebody out there in Python / django land has an idea.

The source svg looks like this: source file

Using ImageMagick 6.6.2-6 2012-08-17 Q16, the cropped / slightly scaled output looks like this (not perfect, but not terrible):

enter image description here

However, using ImageMagick 6.6.9-7 2012-08-17 Q16, the output looks like this:

enter image description here

The actual call I'm making is simply:

with WandImage(blob = self.cover_binary, resolution = 300) as img:
    img.type = self.png_image_type #truecolor
    img.depth = self.png_image_depth #8
    img.resize(self.png_width, self.png_height)
    self.png_output = img.make_blob('png')

I've tried tons of variations of img.resize() with different blur and filter settings, (blur values between 0 and 1, filter values of none, triangle, point, lanczos, lanczossharp), but I'm just not able to get the preview rendering with the small line detail. I'm at my wits end and about to go with a solution that I don't like, and am hoping somebody out there might be able to give me some insight on what I'm missing here. It already took me a few hours just to realize that ImageMagick is likely the culprit since that's literally the only thing different between my local box running the older version and the staging box that has the newer version.


Source: (StackOverflow)