How to use the wand.api.library.MagickSetSize 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 emcconville / wand / wand / image.py View on Github external
elif not isinstance(top, numbers.Integral):
            raise TypeError('top must be an integer, not ' + repr(top))
        elif width is not None and not isinstance(width, numbers.Integral):
            raise TypeError('width must be an integer, not ' + repr(width))
        elif height is not None and not isinstance(height, numbers.Integral):
            raise TypeError('height must be an integer, not ' + repr(height))
        elif font is not None and not isinstance(font, Font):
            raise TypeError('font must be a wand.font.Font, not ' + repr(font))
        elif gravity is not None and compat.text(gravity) not in GRAVITY_TYPES:
            raise ValueError('invalid gravity value')
        if width is None:
            width = self.width - left
        if height is None:
            height = self.height - top
        with Image() as textboard:
            library.MagickSetSize(textboard.wand, width, height)
            textboard.font = font or self.font
            textboard.gravity = gravity or self.gravity
            with Color('transparent') as background_color:
                library.MagickSetBackgroundColor(textboard.wand,
                                                 background_color.resource)
            textboard.read(filename=b'caption:' + text.encode('utf-8'))
            self.composite(textboard, left, top)
github emcconville / wand / wand / image.py View on Github external
raise ValueError(repr(filter) + ' is an invalid filter type; '
                                 'choose on in ' + repr(FILTER_TYPES))
        elif (isinstance(filter, numbers.Integral) and
              not (0 <= filter < len(FILTER_TYPES))):
            raise ValueError(repr(filter) + ' is an invalid filter type')
        blur = ctypes.c_double(float(blur))
        if self.animation:
            self.wand = library.MagickCoalesceImages(self.wand)
            library.MagickSetLastIterator(self.wand)
            n = library.MagickGetIteratorIndex(self.wand)
            library.MagickResetIterator(self.wand)
            for i in xrange(n + 1):
                library.MagickSetIteratorIndex(self.wand, i)
                library.MagickResizeImage(self.wand, width, height,
                                          filter, blur)
            library.MagickSetSize(self.wand, width, height)
        else:
            r = library.MagickResizeImage(self.wand, width, height,
                                          filter, blur)
            library.MagickSetSize(self.wand, width, height)
            if not r:
                self.raise_exception()
github emcconville / wand / wand / image.py View on Github external
repr(width))
        elif height < 1:
            raise ValueError('height must be a natural number, not ' +
                             repr(height))
        if self.animation:
            self.wand = library.MagickCoalesceImages(self.wand)
            library.MagickSetLastIterator(self.wand)
            n = library.MagickGetIteratorIndex(self.wand)
            library.MagickResetIterator(self.wand)
            for i in xrange(n + 1):
                library.MagickSetIteratorIndex(self.wand, i)
                library.MagickSampleImage(self.wand, width, height)
            library.MagickSetSize(self.wand, width, height)
        else:
            r = library.MagickSampleImage(self.wand, width, height)
            library.MagickSetSize(self.wand, width, height)
            if not r:
                self.raise_exception()
github emcconville / wand / wand / image.py View on Github external
def height(self, height):
        if height is not None and not isinstance(height, numbers.Integral):
            raise TypeError('height must be a integral, not ' + repr(height))
        library.MagickSetSize(self.wand, self.width, height)
github emcconville / wand / wand / image.py View on Github external
repr(height))
        elif width < 1:
            raise ValueError('width must be a natural number, not ' +
                             repr(width))
        elif height < 1:
            raise ValueError('height must be a natural number, not ' +
                             repr(height))
        if self.animation:
            self.wand = library.MagickCoalesceImages(self.wand)
            library.MagickSetLastIterator(self.wand)
            n = library.MagickGetIteratorIndex(self.wand)
            library.MagickResetIterator(self.wand)
            for i in xrange(n + 1):
                library.MagickSetIteratorIndex(self.wand, i)
                library.MagickSampleImage(self.wand, width, height)
            library.MagickSetSize(self.wand, width, height)
        else:
            r = library.MagickSampleImage(self.wand, width, height)
            library.MagickSetSize(self.wand, width, height)
            if not r:
                self.raise_exception()
github emcconville / wand / wand / image.py View on Github external
def width(self, width):
        if width is not None and not isinstance(width, numbers.Integral):
            raise TypeError('width must be a integral, not ' + repr(width))
        library.MagickSetSize(self.wand, width, self.height)
github acmanderson / content-aware-santa / content_aware_image.py View on Github external
height = int(original_height * float(height) / 100)
                start_width = int(original_width * float(start_width) / 100)
                start_height = int(original_height * float(start_height) / 100)

            if not use_slow_scaling:
                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 emcconville / wand / wand / image.py View on Github external
raise ValueError(repr(filter) + ' is an invalid filter type')
        blur = ctypes.c_double(float(blur))
        if self.animation:
            self.wand = library.MagickCoalesceImages(self.wand)
            library.MagickSetLastIterator(self.wand)
            n = library.MagickGetIteratorIndex(self.wand)
            library.MagickResetIterator(self.wand)
            for i in xrange(n + 1):
                library.MagickSetIteratorIndex(self.wand, i)
                library.MagickResizeImage(self.wand, width, height,
                                          filter, blur)
            library.MagickSetSize(self.wand, width, height)
        else:
            r = library.MagickResizeImage(self.wand, width, height,
                                          filter, blur)
            library.MagickSetSize(self.wand, width, height)
            if not r:
                self.raise_exception()
github emcconville / wand / wand / image.py View on Github external
with Color('transparent') as bg:  # FIXME: parameterize this
                    result = library.MagickSetBackgroundColor(self.wand,
                                                              bg.resource)
                    if not result:
                        self.raise_exception()

                # we allow setting the width, height and depth
                # (needed for loading raw data)
                if width is not None and height is not None:
                    if not isinstance(width, numbers.Integral) or width < 1:
                        raise TypeError('width must be a natural number, not ' +
                                        repr(width))
                    if not isinstance(height, numbers.Integral) or height < 1:
                        raise TypeError('height must be a natural number, not ' +
                                        repr(height))
                    library.MagickSetSize(self.wand, width, height)
                if depth is not None:
                    library.MagickSetDepth(self.wand, depth)

                if file is not None:
                    if format:
                        library.MagickSetFilename(self.wand,
                                                  b'buffer.' + format)
                    self.read(file=file, resolution=resolution)
                elif blob is not None:
                    if format:
                        library.MagickSetFilename(self.wand,
                                                  b'buffer.' + format)
                    self.read(blob=blob, resolution=resolution)
                elif filename is not None:
                    if format:
                        raise TypeError(