

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)
#Rounded white rectangle png full
→You cannot use “For Reference Only” content in any manner that entails advertising, marketing or commercialization of any product or service.įor Full Edition of Pikbest License Agreement, please click here to the Pikbest License page.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): →You cannot imply that the content is created or claimed to be the copyright of the artwork by you or someone other than the copyright holder of the Pikbest content. →You can only use an Item for lawful purposes. You can’tĬlaim trademark or service mark rights over an Item within the End Product created using that Item. →You cannot use the content in the Pikbest Content (totally or partially) in any trademark, logo or part of the same. →You cannot use the content in the Pikbest Content in printed or electronic items aimed to be resold. →You cannot resell, redistribute, access, share or transfer Pikbest Content. While privileges are different upon different user types, there are some restrictions which are applicable to all Pikbest users. The Pikbest Authorization differs upon different situations. Pikbest authorizes the User in a non-transferable, non-exclusive manner and on a worldwide basis for the duration of the relevant rights to download, use and modify the Pikbest Content, as expressly permitted by the applicable license and subject to this document.
