workvorti.blogg.se

Rounded white rectangle png
Rounded white rectangle png





rounded white rectangle png

Keywords: Python, image processing, round corners, rounded corners, border, SVG, cairo, cairosvg, SVG to PNG, SVG as PNG, SVG to PIL, PIL, Pillow. gravity center -compose over -composite result.png Magick -size $ xc:black -fill white -draw "roundrectangle 0,0,$iw,$ih 20,20" monsters.jpg -compose darken -composite \) \ # Calculate size of output image, assumes thickness=10 Read iw ih < <(identify -format "%w %h" monsters.jpg) Just in case anyone wants an ImageMagick solution: #!/bin/bash With a 15x15 median filter, you get this: You can also create a rounded corner by drawing a white rectangle in a black box and running a median filter, or some morphological erosion, over it.Here are outer, inner and expanded - as you can see they are all the same size as each other for easy composing atop each other. You can play with rx and ry to change the radius of the corners. # Paste expanded image onto outer black border using inner white rectangle as mask # Expand original canvas with black to match output sizeĮxpanded = ImageOps.expand(im, border=thickness, fill=(0,0,0)).convert('RGB') Inner = Image.open(BytesIO(png)).convert('L') # Draw inner white rounded rect, offset by thickness into memory as PNG # Draw outer black rounded rect into memory as PNG

rounded white rectangle png

# Get input image width and height, and calculate output width and height I fancied my hand at drawing rounded rectangles with SVG for a change - not least because somebody thinks I always use ImageMagick -) #!/usr/bin/env python3

ROUNDED WHITE RECTANGLE PNG CODE

It's the same concept as used in my other answer with some more code on the correct transparency stuff. Img = cv2.imread('path/to/your/image.png') New_image = new_image * (1 - mask) + temp * mask Mask = np.stack((mask, mask, mask), axis=2) # Create new image (three-channel hardcoded here.) :return: new image as NumPy array with rounded corners photos, to the method and get the image including a border with rounded corners, and transparency outside the border! import cv2ĭef rect_with_rounded_corners(image, r, t, c): After some discussion with Mark in the comments on my first answer, I decided to make another solution using OpenCV and NumPy, which is able to easily feed some real images, e.g.







Rounded white rectangle png