def convert(source_fh, source_type, dest_type, dest_size): """somewhat like convert(1)""" i = Image(source_fh, source_type) if not i.select(dest_size): print "bad size" i.alpha(True) i.scale(dest_size) i.alpha(True) result = i.dump(dest_type) return result
def test_get_units(): w = Image() assert None == w.units api.MagickNewImage(w._wand, 100, 100, api.NewPixelWand()) assert None == w.units api.MagickSetImageUnits(w._wand, api.PixelsPerInchResolution) assert PIXELS_PER_INCH == w.units
def test_get_format(): w = Image() assert None == w.format api.MagickNewImage(w._wand, 100, 100, api.NewPixelWand()) assert None == w.format api.MagickSetImageFormat(w._wand, 'PNG') assert 'PNG' == w.format
def test_constructor_with_file(): w = Image(StringIO(GIF)) assert 'GIF' == w.format assert (1,1) == w.size size = api.size_t() b = api.MagickGetImageBlob(w._wand, size) assert GIF == ''.join([chr(b[i]) for i in range(0, size.value + 1)])
import copy import random from pythonmagickwand.image import Image from pythonmagickwand.wand import LANCZOS_FILTER, TRANSPARENT_COLORSPACE from pythonmagickwand.color import Color, BLACK, YELLOW, TRANSPARENT YELLOW = Color('#ffcc33') m = Image('monkey.png') m.opaque_paint(BLACK, YELLOW, 10) m.scale((500,500)) m.compression_quality = 95 im = Image() im.colorspace = TRANSPARENT_COLORSPACE im.size = (4000, 800) im.format = 'PNG' im.background_color = TRANSPARENT _w, _h = im.size num = range(3000) for i in num: ratio = (i+1.)/len(num) random.seed() _min = int(100*ratio+100) w = random.randint(_min, max(int(400*ratio), _min)) c = copy.copy(m) c.scale((w, w)) c.rotate(random.randint(0, 360), TRANSPARENT) c.modulate(brightness=i*25/len(num) + 75)
from pythonmagickwand.image import Image i = Image('./assets/064fa8ad-4b88-452f-a110-68f1250be0c3_texture.jp2') i.format = 'PNG' i.flip() i.save('flip.png')
def test_get_colorspace(): w = Image() assert None == w.colorspace w = setup() api.MagickSetImageColorspace(w._wand, CMYK_COLORSPACE) assert CMYK_COLORSPACE == w.colorspace
def setup(): i = Image() api.MagickNewImage(i._wand, 100, 100, api.NewPixelWand()) return i
def test_constructor_with_eps_file(): w = Image(StringIO(EPS)) assert 'EPS' == w.format size = api.size_t() b = api.MagickGetImageBlob(w._wand, size) assert EPS == ''.join([chr(b[i]) for i in range(0, size.value + 1)])