How to use the wand.exceptions.MissingDelegateError 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 steder / giraffe / test_giraffe.py View on Github external
def test_fit_liquid(self):
        pipeline = [giraffe.ImageOp('liquid', {'width': 100, 'height': 100})]
        try:
            img = giraffe.process_image(self.image, pipeline)
        except MissingDelegateError:
            pytest.skip("ImageMagick doesn't have Liquid Rescale support compiled in")
        self.assertEqual(img.size, (100, 100))
github emcconville / wand / wandtests / image.py View on Github external
def liquid_rescale():
    def assert_equal_except_alpha(a, b):
        with a:
            with b:
                assert (a.red == b.red and
                        a.green == b.green and
                        a.blue == b.blue)
    with Image(filename=asset('beach.jpg')) as orig:
        with orig.clone() as img:
            try:
                img.liquid_rescale(600, 600)
            except MissingDelegateError:
                warnings.warn('skip liquid_rescale test; has no LQR delegate')
            else:
                assert img.size == (600, 600)
                for x in 0, -1:
                    for y in 0, -1:
                        assert_equal_except_alpha(img[x, y], img[x, y])
github emcconville / wand / wand / image.py View on Github external
"""
        if not isinstance(width, numbers.Integral):
            raise TypeError('width must be an integer, not ' + repr(width))
        elif not isinstance(height, numbers.Integral):
            raise TypeError('height must be an integer, not ' + repr(height))
        elif not isinstance(delta_x, numbers.Real):
            raise TypeError('delta_x must be a float, not ' + repr(delta_x))
        elif not isinstance(rigidity, numbers.Real):
            raise TypeError('rigidity must be a float, not ' + repr(rigidity))
        library.MagickLiquidRescaleImage(self.wand, int(width), int(height),
                                         float(delta_x), float(rigidity))
        try:
            self.raise_exception()
        except MissingDelegateError as e:
            raise MissingDelegateError(
                str(e) + '\n\nImageMagick in the system is likely to be '
                'impossible to load liblqr.  You might not install liblqr, '
github hauxir / imgpush / app / app.py View on Github external
output_filename = os.path.basename(tmp_filepath) + f".{output_type}"
    output_path = os.path.join(settings.IMAGES_DIR, output_filename)

    try:
        with Image(filename=tmp_filepath) as img:
            img.strip()
            if output_type not in ["gif"]:
                with img.sequence[0] as first_frame:
                    with Image(image=first_frame) as first_frame_img:
                        with first_frame_img.convert(output_type) as converted:
                            converted.save(filename=output_path)
            else:
                with img.convert(output_type) as converted:
                    converted.save(filename=output_path)
    except MissingDelegateError:
        error = "Invalid Filetype"
    finally:
        if os.path.exists(tmp_filepath):
            os.remove(tmp_filepath)

    if error:
        return jsonify(error=error), 400

    return jsonify(filename=output_filename)
github cubaneorg / cubane / cubane / lib / image.py View on Github external
import os
import re
import base64
import hashlib
import tempfile
import subprocess

# wand
from wand.image import Image as WandImage
from wand.color import Color as WandColor
from wand.drawing import Drawing as WandDrawing
from wand import exceptions as wand_exceptions


NOT_AN_IMAGE_WAND_EXCEPTIONS = (
    wand_exceptions.MissingDelegateError,
    wand_exceptions.BlobError,
    wand_exceptions.CorruptImageError,
    wand_exceptions.TypeError,
    wand_exceptions.FileOpenError,
    wand_exceptions.OptionError
)


SUPPORTED_SVG_STYLE_OVERWRITES = [
    'fill',
    'stroke'
]


def open_image(filename):
    """
github acmanderson / content-aware-santa / content_aware_image.py View on Github external
library.MagickLiquidRescaleImage(self.wand, width, height, float(delta_x), float(rigidity))
                library.MagickSampleImage(self.wand, original_width, original_height)
            else:
                # upscaling the image before downscaling it with liquid rescale can produce different/better results,
                # but is a lot slower
                library.MagickSampleImage(self.wand,
                                          int(float(original_width) / width * original_width),
                                          int(float(original_height) / height * original_height))
                library.MagickLiquidRescaleImage(self.wand, original_width, original_height, float(delta_x),
                                                 float(rigidity))
                library.MagickSetSize(self.wand, original_width, original_height)

        try:
            self.raise_exception()
        except exceptions.MissingDelegateError as e:
            raise exceptions.MissingDelegateError(
                str(e) + '\n\nImageMagick in the system is likely to be '
                         'impossible to load liblqr.  You might not install liblqr, '
github steder / giraffe / giraffe.py View on Github external
def stubbornly_load_image(content, headers, path):
    try:
        return Image(blob=BytesIO(content))
    except wand.exceptions.MissingDelegateError as orig_e:
        try:
            return Image(blob=BytesIO(content), format='ico')
        except wand.exceptions.MissingDelegateError:
            raise orig_e
github dlau / mineye / server.py View on Github external
BANK_PATH,
                guid
            )
            dstfile_thumb = join(
                BANK_THUMB_PATH,
                guid
            )
            file.save(tmpfile)
            try:
                with wand.image.Image(filename=tmpfile) as img:
                    img.save(filename=dstfile)
                    #will potentially produce some funny results with extremely wide/oblong images
                    img.resize(256, 256)
                    img.save(filename=dstfile_thumb)
                    im.add_image(dstfile_thumb)
            except wand.exceptions.MissingDelegateError:
                return 'input is not a valid image', 500
            return '', 200

    elif request.method == 'GET':
        limit = 10
        try:
            limit = int(request.args.get('limit', '10'))
        except ValueError:
            pass
        #note, will spit back any non dir
        files = get_bank_images()
        return json.dumps({
            'count' : im.get_count(),
            'latest' : ['/'+f for f in files[0:limit]]
            })
    return '', 400
github jazzband / sorl-thumbnail / sorl / thumbnail / engines / wand_engine.py View on Github external
def is_valid_image(self, raw_data):
        '''
        Wand library makes sure when opening any image that is fine, when
        the image is corrupted raises an exception.
        '''

        try:
            Image(blob=raw_data)
            return True
        except (exceptions.CorruptImageError, exceptions.MissingDelegateError):
            return False
github emcconville / wand / wand / image.py View on Github external
.. _Seam carving: http://en.wikipedia.org/wiki/Seam_carving

        """
        if not isinstance(width, numbers.Integral):
            raise TypeError('width must be an integer, not ' + repr(width))
        elif not isinstance(height, numbers.Integral):
            raise TypeError('height must be an integer, not ' + repr(height))
        elif not isinstance(delta_x, numbers.Real):
            raise TypeError('delta_x must be a float, not ' + repr(delta_x))
        elif not isinstance(rigidity, numbers.Real):
            raise TypeError('rigidity must be a float, not ' + repr(rigidity))
        library.MagickLiquidRescaleImage(self.wand, int(width), int(height),
                                         float(delta_x), float(rigidity))
        try:
            self.raise_exception()
        except MissingDelegateError as e:
            raise MissingDelegateError(
                str(e) + '\n\nImageMagick in the system is likely to be '
                'impossible to load liblqr.  You might not install liblqr, '