Fill an image with pre-defined pattern with Wand
I have an image (like that: mask) and two integers, which represents a final image width & height. According to Wand's documentation Open empty image: with Image(width=200, height=100) as img: img.save(filename='200x100-transparent.png') It will result in an empty image with transparent background. Now, the question is: How to create a same empty image, but with mask image as background pattern? The composite CLI command itself has a following operator: -tile repeat composite operation across and down image But how to achieve the same with Wand?
Well, after looking on ImageMagick's Composite source code itself, it became clear, that the Wand-driven solution should look like: with Image(width=x, height=y) as img: for x in xrange(0, img.width, crop_mask_path.width): for y in xrange(0, img.height, crop_mask_path.height): img.composite_channel('default_channels', crop_mask_path, 'over', x, y) img.save(filename='patterned_image.png')
Building out the title iterator is the best solution in my opinion. However another hackish method would be to invoke the tile: protocol, and allow the internal ImageMagick methods to handle composites. You'll lose the control inherited by DIY, but gain some performance on optimized IM systems. from wand.image import Image from wand.api import library with Image() as img: # Same as `-size 400x400' needed by tile: protocol. library.MagickSetOption(img.wand, 'size', '400x400') # Prefix filename with `tile:' protocol. img.read(filename='tile:rose.png') img.save(filename='tile_rose.png')
How to check if a date time is before midday
Merge rows based on values and key string in awk, sed or python
i find the files at the end empty ,python
How do I prevent my FOR loop from ending too early?
PyInstaller 2.1 import custom package
Python: Read File and append a lot of list of 28 lines
Numba Matrix Vector multiplication
How to improve very inefficient numpy code for calculating correlation
Flask-strange routing issue
Upgrade path for re-usable apps with South AND django 1.7 migrations
Making scikit-learn train on all training data after cross-validation
matplotlib does not display latex fonts correctly
How to use py2exe with third-party libraries
How to extract two numbers from input line and tab delimit them?
Copy selected lines of text from one file to another with command line argument with or without spaces
TypeError: can't use a string pattern on a bytes-like object