pillow

10个超有趣的Python项目,你会哪个?

让人想犯罪 __ 提交于 2020-04-20 13:37:39
前言: Python可谓是现在很多人正在学或者想学的一个脚本语言了,提到学习自然就少不了拿项目练手,可是一般的项目根本提不起兴趣嘛,这10个项目可是非常有趣的,不信你看看。 【Python 图片转字符画】 用 50 行 Python 代码完成图片转字符画小工具。通过实验将学习到 Linux 命令行操作,Python 基础,pillow 库的使用,argparse 库的使用。 效果图 【使用 Python 生成分形图片】 这里特别注意:不管你是为了Python就业还是兴趣爱好,记住:项目开发经验永远是核心,如果你没有2020最新python入门到高级实战视频教程,可以去小编的Python交流.裙 :七衣衣九七七巴而五(数字的谐音)转换下可以找到了,里面很多新python教程项目,还可以跟老司机交流讨教! 用Python Turtle 模块,通过画出分形树(Fractal tree),科赫雪花曲线(Koch snowflake)和龙形曲线(Dragon curve)这三种曲线来加强对递归的认识。 效果图一 【Python3 色情图片识别】 使用 Python3 去识别图片是否为色情图片,我们会使用到 PIL 这个图像处理库,会编写算法来划分图像的皮肤区域。其中涉及到Python 3 基础知识,肤色像素检测与皮肤区域划分算法,Pillow及argparse的使用。 效果图一

Django学习笔记(17)——BBS+Blog项目开发(1)验证码功能的实现

这一生的挚爱 提交于 2020-04-18 00:37:38
  本文主要学习验证码功能的实现,为了项目BBS+Blog项目打下基础。   为了防止机器人频繁登陆网站或者破坏分子恶意登陆,很多用户登录和注册系统都提供了图形验证码功能。   验证码(CAPTCHA)是“Completely Automated Public Turing test to tell Computers and Humans Apart”(全自动区分计算机和人类的图灵测试)的缩写,是一种区分用户是计算机还是人的公共全自动程序。可以防止恶意破解密码、刷票、论坛灌水,有效防止某个黑客对某一个特定注册用户用特定程序暴力破解方式进行不断的登陆尝试。   图形验证码的历史比较悠久,到现在已经有点英雄末路的味道了。因为机器学习、图像识别的存在,机器人已经可以比较正确的识别图像内的字符了。但不管怎么说,作为一种防御手段,至少还是可以抵挡一些低级入门的攻击手段,抬高了攻击者的门槛。 验证码功能实现方法1——完整的验证码实现流程 1, 验证码前端画布页面生成   那么下面我们将依次生成验证码这种画布,左边框是输入验证码的内容,右边框是设计验证码。 1.1,直接读取图片   首先,我们需要了解读取图片的方法。 # 方式一 with open('kd1.jpg', 'rb') as f: data = f.read() return HttpResponse(data)  

Measuring width of text (Python/PIL)

…衆ロ難τιáo~ 提交于 2020-03-17 04:38:49
问题 I'm using the following two methods to calculate a sample string's rendered width for a set font-type and size: font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 14) sample = "Lorem ipsum dolor sit amet, partem periculis an duo, eum lorem paulo an, mazim feugiat lobortis sea ut. In est error eirmod vituperata, prima iudicabit rationibus mel et. Paulo accumsan ad sit, et modus assueverit eum. Quod homero adversarium vel ne, mel noster dolorum te, qui ea senserit

Measuring width of text (Python/PIL)

我的梦境 提交于 2020-03-17 04:38:04
问题 I'm using the following two methods to calculate a sample string's rendered width for a set font-type and size: font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 14) sample = "Lorem ipsum dolor sit amet, partem periculis an duo, eum lorem paulo an, mazim feugiat lobortis sea ut. In est error eirmod vituperata, prima iudicabit rationibus mel et. Paulo accumsan ad sit, et modus assueverit eum. Quod homero adversarium vel ne, mel noster dolorum te, qui ea senserit

一行命令自动戴上口罩

拈花ヽ惹草 提交于 2020-02-27 12:14:40
本文同步发表于 Prodesire 公众号 和 Prodesire 博客 。 前言 2019 年底开始蔓延的新型肺炎疫情牵动人心,作为个体,我们力所能及的就是尽量待在家中少出门。 看到一些朋友叫设计同学帮忙给自己的头像戴上口罩,作为技术人,心想一定还有更多人有这样的诉求,不如开发一个简单的程序来实现这个需求,也算是帮助设计姐姐减少工作量。 于是花了些时间,写了一个叫做 face-mask 的命令行工具,能够轻松的给图片中的人像戴上口罩,而且口罩的方向和大小都是适应人脸的哦~ 使用 安装 face-mask 确保 Python 版本在 3.6 及以上 pip install face-mask 使用 face-mask 直接指定图片路径即可为图片中的人像戴上口罩,并会生成一个新的图片(额外有 -with-mask 后缀): face-mask /path/to/face/picture 通过指定 --show 选项,还可以使用默认图片查看器打开新生成的图片: face-mask /path/to/face/picture --show 效果 给一个人戴上口罩 给多个人戴上口罩 给动漫人物戴上口罩 实现 思路 要想实现上面的效果,我们应该怎么做?不妨这么想: 首先是识别出人的鼻子(nose_bridge)和脸轮廓(chin) 通过脸轮廓确定出脸左点(chin_left_point)

Convert image loaded as binary string into numpy array

孤者浪人 提交于 2020-02-24 16:56:27
问题 Is there a method to convert an image, that is loaded as a binary string, into a numpy array of size (im_height, im_width, 3)? Something like this: # read image as binary string with open(img_path, "rb") as image_file: image_string = image_file.read() # convert image string to numpy image_np = convert_binary_string_to_numpy(image_string) How would that conversion function look like? I'm working with decryption, thus I need to work with binary strings. Thanks! 回答1: import io import numpy as np

How to get the font pixel height using PIL' ImageFont?

删除回忆录丶 提交于 2020-01-31 05:00:07
问题 I am using PIL' ImageFont module to load fonts to generate text images. I want the text to tightly bound to the edge, however, when using the ImageFont to get the font height, It seems that it includes the character's padding. As the red rectangle indicates. c = 'A' font = ImageFont.truetype(font_path, font_size) width = font.getsize(c)[0] height = font.getsize(c)[1] im = Image.new("RGBA", (width, height), (0, 0, 0)) draw = ImageDraw.Draw(im) draw.text((0, 0), 'A', (255, 255, 255), font=font)

Error while converting webp image file to jpg in python

有些话、适合烂在心里 提交于 2020-01-29 05:09:12
问题 I have written small program to convert webp to jpg in python import imghdr from PIL import Image im = Image.open("unnamed.webp").convert("RGB") im.save("test.jpg","jpeg") when executing it gives me following error No handlers could be found for logger "PIL.ImageFile" Traceback (most recent call last): File "webptopng.py", line 3, in <module> im = Image.open("unnamed.webp").convert("RGB") File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2286, in open % (filename if filename