How to use the wand.image function in Wand

To help you get started, we’ve selected a few Wand examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pywikibot-catfiles / file-metadata / file_metadata / image / svg_file.py View on Github external
def fetch(self, key=''):
        if key == 'filename_raster':
            # SVG files are not raster graphics, hence we convert it to one
            # and use that instead.
            with wand.image.Image(filename=self.fetch('filename')) \
                    as svg_image:
                svg_image.format = 'png'
                fd, name = tempfile.mkstemp(
                    suffix=os.path.split(self.fetch('filename'))[-1] + '.png',
                    prefix='tmp_file_metadata')
                os.close(fd)
                svg_image.save(filename=name)
                self.temp_filenames.add(name)
                return name

        return super(SVGFile, self).fetch(key)
github wagtail / Willow / willow / backends / wand.py View on Github external
def import_wand_image():
    import wand.image
    return wand.image
github TrustyJAID / Trusty-cogs-archive / notsobot / notsobot.py View on Github external
def do_woow(self, b):
        f = BytesIO()
        f2 = BytesIO()
        with wand.image.Image(file=b, format='png') as img:
            h1 = img.clone()
            width = int(img.width) if int(img.width) > 0 else 1
            h1.crop(width=width, height=int(img.height/2), gravity='north')
            h2 = h1.clone()
            h2.rotate(degree=180)
            h2.flop()
            h1.save(file=f)
            h2.save(file=f2)
        f.seek(0)
        f2.seek(0)
        list_im = [f, f2]
        imgs = [PIL.Image.open(i).convert('RGBA') for i in list_im]
        min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1]
        imgs_comb = np.vstack((np.asarray(i.resize(min_shape)) for i in imgs))
        imgs_comb = PIL.Image.fromarray(imgs_comb)
        final = BytesIO()
github NotSoSuper / NotSoBot / mods / Fun.py View on Github external
def do_magik(self, scale, *imgs):
		try:
			list_imgs = []
			exif = {}
			exif_msg = ''
			count = 0
			for img in imgs:
				i = wand.image.Image(file=img)
				i.format = 'jpg'
				i.alpha_channel = True
				if i.size >= (3000, 3000):
					return ':warning: `Image exceeds maximum resolution >= (3000, 3000).`', None
				exif.update({count:(k[5:], v) for k, v in i.metadata.items() if k.startswith('exif:')})
				count += 1
				i.transform(resize='800x800>')
				i.liquid_rescale(width=int(i.width * 0.5), height=int(i.height * 0.5), delta_x=int(0.5 * scale) if scale else 1, rigidity=0)
				i.liquid_rescale(width=int(i.width * 1.5), height=int(i.height * 1.5), delta_x=scale if scale else 2, rigidity=0)
				magikd = BytesIO()
				i.save(file=magikd)
				magikd.seek(0)
				list_imgs.append(magikd)
			if len(list_imgs) > 1:
				imgs = [PIL.Image.open(i).convert('RGBA') for i in list_imgs]
				min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1]
github wagtail / Willow / willow / plugins / wand.py View on Github external
def _wand_image():
    import wand.image
    return wand.image
github tsurumeso / waifu2x-chainer / lib / iproc.py View on Github external
def array_to_wand(src):
    assert isinstance(src, np.ndarray)
    with io.BytesIO() as buf:
        tmp = Image.fromarray(src).convert('RGB')
        tmp.save(buf, 'PNG', compress_level=0)
        dst = wand.image.Image(blob=buf.getvalue())
    return dst
github tsurumeso / waifu2x-chainer / lib / iproc.py View on Github external
def jpeg(src, sampling_factor='1x1,1x1,1x1', quality=90):
    src.format = 'jpg'
    src.compression_quality = quality
    src.options['jpeg:sampling-factor'] = sampling_factor
    return wand.image.Image(blob=src.make_blob())
github so-rose / openlut / openlut.py View on Github external
def openWand(path) :
		'''
		Open a file using the Wand ImageMagick binding.
		'''
		with wand.image.Image(filename=path) as img:
			#Quick inverse sRGB transform, to undo what Wand did.
			img.colorspace = 'srgb'
			img.transform_colorspace('rgb')
			
			img.colorspace = 'srgb' if img.format == 'DPX' else 'rgb' #Fix for IM's dpx bug.
			
			return ColMap.fromIntArray(np.fromstring(img.make_blob("RGB"), dtype='uint{}'.format(img.depth)).reshape(img.height, img.width, 3))