参考链接:https://stackoverflow.com/questions/11287402/how-to-round-corner-a-logo-without-white-backgroundtransparent-on-it-using-pi

用了三种方法,第三种方法效果最好,效果如下图:

需要用到两个库:

pip install Pillow
pip install aggdraw

源码如下:

from PIL import Image,ImageDraw,ImageChops
import aggdraw
import os def round_corner_jpg(image, radius):
"""generate round corner for image"""
mask = Image.new('L', image.size) # filled with black by default
draw = aggdraw.Draw(mask)
brush = aggdraw.Brush('white')
width, height = mask.size
#upper-left corner
draw.pieslice((0,0,radius*2, radius*2), 90, 180, None, brush)
#upper-right corner
draw.pieslice((width - radius*2, 0, width, radius*2), 0, 90, None, brush)
#bottom-left corner
draw.pieslice((0, height - radius * 2, radius*2, height),180, 270, None, brush)
#bottom-right corner
draw.pieslice((width - radius * 2, height - radius * 2, width, height), 270, 360, None, brush)
#center rectangle
draw.rectangle((radius, radius, width - radius, height - radius), brush)
#four edge rectangle
draw.rectangle((radius, 0, width - radius, radius), brush)
draw.rectangle((0, radius, radius, height-radius), brush)
draw.rectangle((radius, height-radius, width-radius, height), brush)
draw.rectangle((width-radius, radius, width, height-radius), brush)
draw.flush()
image = image.convert('RGBA')
image.putalpha(mask)
return image def get_filePath_fileName_fileExt(fileUrl):
"""
获取文件路径, 文件名, 后缀名
:param fileUrl:
:return:
"""
filepath, tmpfilename = os.path.split(fileUrl)
shotname, extension = os.path.splitext(tmpfilename)
return filepath, shotname, extension if __name__ == '__main__':
picLocation = 'Sina1.png'
im = Image.open(picLocation)
im = round_corner_jpg(im, 20)
im.save(get_filePath_fileName_fileExt(picLocation)[1]+'_round.png')

顺便安利一个免费的开源的看图片的软件:https://imageglass.org/

前面两种方法效果都不好

第一种方法锯齿比较明显

第二种方法有白色区域:

python 直角图标生成圆角图标的更多相关文章

  1. python实现基于两张图片生成圆角图标效果的方法

    python实现基于两张图片生成圆角图标效果的方法 这篇文章主要介绍了python实现基于两张图片生成圆角图标效果的方法,实例分析了Python使用pil模块进行图片处理的技巧,分享给大家供大家参考. ...

  2. DSAPI 生成桌面图标(带数字)

    功能:在桌面上创建一个带有指定数字的图标. 效果图: 生成的ICO图标 代码 Private Sub 生成桌面图标(消息数量 As Integer) Try Dim B As New Bitmap(M ...

  3. Font Combiner – 自定义网页字体和图标生成工具

    Font Combiner 是一个功能丰富的 Web 字体生成工具和字体改进工具,提供字距调整.构造子集.各种提示选项和自定义字体字形组合.您可以生成您自己的自定义字体的格式和文件大小. 另外还有成千 ...

  4. 详解使用icomoon生成字体图标的方法并应用

    原文:http://blog.csdn.net/u013938465/article/details/50680468 最近项目大量用到字体图标,大家也知道,字体图标任意缩放不会失真,也大大减少请求数 ...

  5. Flatty Shadow在线为Icon图标生成长阴影效果。

    Flatty Shadow在线为Icon图标生成长阴影效果. Flatty Shadow 彩蛋爆料直击现场 Flatty Shadow在线为Icon图标生成长阴影效果.

  6. icomoon:生成字体图标的方法并应用

    字体图标任意缩放不会失真,也大大减少请求数量,非常好用. 在线生成工具:https://icomoon.io/app/#/select 在线SVG图库(阿里),  用于导入:http://www.ic ...

  7. App 图标设计 - 圆角透明效果(0 基础使用 PS)

    App 图标设计 - 圆角透明效果(0 基础使用 PS) 方法: 如果你有些基础,就不必看图文教程了: 1.使用圆角矩形工具选中,设置圆角尺寸[例如:1024*1024 px(圆角:160 px)] ...

  8. 使用icomoon把svg图片生成字体图标

    今天看了使用icomoon来将svg转换成图标字体,本来是不会使用别人给的svg,也不清楚具体的好处是什么,查了svg以后,越来越懵,svg挺好的为什么要转成图标字体呢. 一.SVG介绍 SVG 是一 ...

  9. ICO图标在线生成,php生成ICO图标在线制作源码

    我们做web系统的时候,每个浏览器的tab这里都会有一个图标,这个图标叫favicon图标,favicon.ico文件放在系统的根目录 如果程序员没有ICO制作工具,那么要如何生成图标呢?可以用程序来 ...

随机推荐

  1. MAC 隐藏功能

    finder 类: shift+ cmd + G  (去指定路径) cmd+↑ (返回) cmd+↓(打开当前选中的文件,如果没有选中的则去选中第一个) cmd+ o (打开当前选中的文件) 以下这些 ...

  2. 【深入学习linux】VMware新建虚拟机教程

    新建虚拟机 1. 点击创建新的虚拟机 2.进入新建向导,选择典型安装,点击下一步 3.为什么不选择第二个选项是因为系统会默认帮助我们安装一个简单配置,这里我们需要学习配置安装所以选择第三项,然后点击下 ...

  3. 迁移Git项目到Gitlab

    假定Gitlab已经安装, 假定要迁移的Git项目目录为 demo 首先在Gitlab里创建一个新的project, 名称为demo (或者其他名称都可以) 然后在现有的Git项目目录下, 进行以下操 ...

  4. kafka集群部署以及单机部署

      kafka单机部署 一.环境准备 当前环境:centos7.3一台软件版本:kafka_2.12部署目录:/usr/local/kafka启动端口:9092配置文件:/usr/local/kafk ...

  5. Sword 第三方库介绍二

    /* uuid生成 */ #include <stdio.h> #include <stdlib.h> /* calloc()函数头文件 */ #include <ass ...

  6. 数据分析入门——pandas之合并函数merge

    merge有点类似SQL中的join,可以将不同数据集按照某些字段进行合并,得到新的数据集  1.参数一览表: 2.一对一连接:默认情况下,会按照相同字段的进行连接 例如有相同字段emp的两个df,m ...

  7. 持久化机器学习模型(joblib方式)

    import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression ...

  8. python调用kafka服务(使用kafka-python库)

    试验环境: CDH 5.15.1 CentOS 7 Python 3.7.0 kafka 1.1.1 kafka-python :https://pypi.org/project/kafka-pyth ...

  9. python中urllib的urlencode与urldecode

    当url地址含有中文,或者参数有中文的时候,这个算是很正常了,但是把这样的url作为参数传递的时候(最常见的callback),需要把一些中文甚至'/'做一下编码转换. urlencode urlli ...

  10. list<Integer>,Integer[],int[]之间的互转(jdk1.8)

    偶然在开发过程中需要将int[] 转成 List<Integer>,采用了遍历的方式,写的代码实在太多. List<Integer> list = new ArrayList& ...