How to use the wand.image.Color 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 bethlakshmi / GBE2 / cron / image_resize / image_resize.py View on Github external
if ratio == 'm': ratio = ''
        elif ratio =='l': ratio ='!'
        elif ratio =='s': ratio ='>'
        elif ratio =='e': ratio ='<'

    if not (type(files) == type(()) or type(files) == type([])):
        files = [files]
    for f in files:
        print f
        with Image (filename=image_dir+'/'+f) as img:
            if ratio == 'c':
                xx, yy = size.split('x')
                img.transform(resize=size)
                width, height = (int(xx)-img.width)/2, (int(yy)-img.height)/2
                print dir(img)
                img.frame(matte=Color('#010101'), width=width, height=height)
                if img.width != xx or img.height != yy:
                    img.transform(resize=size+'!')
                img.save(filename=mini_dir+'/'+f)
            else:
                img.transform(resize=size+ratio)
                img.save(filename=mini_dir+'/'+f)
github algoo / preview-generator / preview_generator / preview / builder / image__wand.py View on Github external
def image_to_jpeg_wand(
        self, jpeg: typing.Union[str, typing.IO[bytes]], preview_dims: ImgDims
    ) -> BytesIO:
        """
        for jpeg, gif and bmp
        :param jpeg:
        :param size:
        :return:
        """
        self.logger.info("Converting image to jpeg using wand")

        with WImage(file=jpeg, background=Color("white")) as image:

            preview_dims = ImgDims(width=preview_dims.width, height=preview_dims.height)

            resize_dim = compute_resize_dims(
                dims_in=ImgDims(width=image.size[0], height=image.size[1]), dims_out=preview_dims
            )
            image.resize(resize_dim.width, resize_dim.height)
            # INFO - jumenzel - 2019-03-12 - remove metadata, color-profiles from this image.
            image.strip()
            content_as_bytes = image.make_blob("jpeg")
            output = BytesIO()
            output.write(content_as_bytes)
            output.seek(0, 0)
            return output
github jsvine / pdfplumber / pdfplumber / display.py View on Github external
def get_page_image(pdf_path, page_no, resolution):
    """
    For kwargs, see http://docs.wand-py.org/en/latest/wand/image.html#wand.image.Image
    """
    page_path = "{0}[{1}]".format(pdf_path, page_no)
    with wand.image.Image(filename=page_path, resolution=resolution) as img:
        if img.alpha_channel:
            img.background_color = wand.image.Color('white')
            img.alpha_channel = 'background'
        with img.convert("png") as png:
            im = PIL.Image.open(BytesIO(png.make_blob()))
            if "transparency" in im.info:
                converted = im.convert("RGBA").convert("RGB")
            else:
                converted = im.convert("RGB")
            return converted
github bitcraft / PURIKURA / pyrikura / effects.py View on Github external
def make2x6(images):
    """
    create a 2x6 photo trip with 4 photos and a banner on the left side
    expects list of wand Images.
    """
    if not len(images) == 4:
        raise ValueError, 'Must supply exactly 4 images to make strip'

    dpi = 1440
    border_width = 40
    border_color = Color('#000000')
    background_color = Color('#FFFFFF')

    strip_size = 2 * dpi, 6 * dpi
    s = int((strip_size[1]+(3*border_width))/4.0)
    target_size = s-border_width*2, s-border_width*2
    x_off, y_off = strip_size[0] - s - (border_width * 4), 0

    # convert to integers
    strip_size = int(strip_size[0]), int(strip_size[1])

    # generate the blank image
    background = Image(width=strip_size[0],
                       height=strip_size[1],
                       background=background_color)
    
    padding = 0, s
github bitcraft / PURIKURA / pyrikura / effects.py View on Github external
def make2x6(images):
    """
    create a 2x6 photo trip with 4 photos and a banner on the left side
    expects list of wand Images.
    """
    if not len(images) == 4:
        raise ValueError, 'Must supply exactly 4 images to make strip'

    dpi = 1440
    border_width = 40
    border_color = Color('#000000')
    background_color = Color('#FFFFFF')

    strip_size = 2 * dpi, 6 * dpi
    s = int((strip_size[1]+(3*border_width))/4.0)
    target_size = s-border_width*2, s-border_width*2
    x_off, y_off = strip_size[0] - s - (border_width * 4), 0

    # convert to integers
    strip_size = int(strip_size[0]), int(strip_size[1])

    # generate the blank image
    background = Image(width=strip_size[0],
                       height=strip_size[1],
                       background=background_color)
    
    padding = 0, s
github Carleslc / InMangaKindle / manga.py View on Github external
def removeAlpha(image_path):
  with wand.image.Image(filename=image_path) as img:
    if img.alpha_channel:
      img.alpha_channel = 'remove'
      img.background_color = wand.image.Color('white')    
      img.save(filename=image_path)