starengineer.blogg.se

Rounded white rectangle png
Rounded white rectangle png












Mask = Image.new('L', image.size) # filled with black by defaultĭraw.This browser-based program rounds the corners of a PNG picture. Something like: (sorry can't test this right now) You might need to convert the image first with nvert('RGBA') but I think this is unnecessary in later versions of PIL, it does it automatically. Once you have this image, you can replace the return ImageChops.add(mask, image) by image.putalpha(mask) return image and this should cause the image to be transparent in only the black areas of the mask. You will probably also need to use the 'L' mode (greyscale) one. Your mask image looks fine, but I think you want to swap 'white' and 'black', so you have a white rounded rectangle exactly the shape you want your final image to be, on a black background. How do I generate circular thumbnails with PIL? The top answer here provides some good examples: mask might have to be in 'L' mode for this to work correctly, and image should probaby be 'RGBA', but might be automatically converted for you. Have you tried something like image.putalpha(mask) to replace the image's alpha channel with the mask? This seems like it should do what you want. Here is your image, processed with this code, giving transparent corners: Here is the code: import Image, ImageDrawĭraw.ellipse((0, 0, rad * 2 - 1, rad * 2 - 1), fill=255) Save as a png, thus preserving transparency.Put the alpha channel into your image using putalpha().Chop our circle into four pieces (the rounded corners), and place them in the correct corners of the alpha image.Create an image for the alpha channel the same size as your image.Draws a circle with radius, rad, using draw.ellipse().

#ROUNDED WHITE RECTANGLE PNG CODE#

Below is some pretty nice code that will add transparent corners. the write stuff off the pic,and I still can see the white corner in the pic you processed for meįirst off, make sure you are saving your image in a format that supports transparency. I am so sorry.I need the image shape to be ellipse not rectangle,I.E. How can i get rid of the white background or make it invisible? Then I saved the returned image object,however it has white background in the corner #mask = Image.new('RGB', (image.size - radius, image.size - radius))ĭraw.rectangle((0,0,width,height), aggdraw.Brush('white'))ĭraw.pieslice((0,0,radius*2, radius*2), 90, 180, None, brush)ĭraw.pieslice((width - radius*2, 0, width, radius*2), 0, 90, None, brush)ĭraw.pieslice((0, height - radius * 2, radius*2, height),180, 270, None, brush)ĭraw.pieslice((width - radius * 2, height - radius * 2, width, height), 270, 360, None, brush)ĭraw.rectangle((radius, radius, width - radius, height - radius), brush)ĭraw.rectangle((radius, 0, width - radius, radius), brush)ĭraw.rectangle((0, radius, radius, height-radius), brush)ĭraw.rectangle((radius, height-radius, width-radius, height), brush)ĭraw.rectangle((width-radius, radius, width, height-radius), brush) I got a square logo and I need to round_corner it, searched for a while and got the follow code "working": def round_corner_jpg(image, radius):












Rounded white rectangle png