安装PIL

Mac或Linux安装命令:sudo easy_install PIL

如果报错:fatal error: 'freetype/fterrors.h' file not found

Mac下所依赖的FreeType链接变更问题,解决如下:

ln -s /usr/local/include/freetype2 /usr/local/include/freetype

sudo easy_install -U pil

如果出现问题:decoder jpeg not available

卸载你的PIL

下载libjpeg:http://www.ijg.org/files/jpegsrc.v7.tar.gz

安装libjpeg:

$ tar zxvf jpegsrc.v7.tar.gz
$ cd jpeg-7
$ ./configure --enable-shared --enable-static
$ make
$ sudo make install

下载PIL: http://effbot.org/downloads/Imaging-1.1.7.tar.gz

编辑setup.py,设置:

JPEG_ROOT = libinclude("/usr/local")

ZLIB_ROOT = libinclude("/usr/local")

安装PIL

$ python setup.py build
$ sudo python setup.py install --optimize=1
$ python selftest.py - Run the selftest to confirm PIL is installed ok
$ sudo python setup.py install

重启IDLE

使用例可参考:

实例

详细了解PIL,请参考PIL官方文档:

http://effbot.org/imagingbook/

Qrcode:生成二维码

安装 qrcode:sudo easy_install qrcode

测试代码(在命令行输入):qr "test" > test.png

python代码:

import Image
import qrcode qr = qrcode.QRCode(
version=2,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=1
)
qr.add_data("http://wx341.vshangtong.com/wxapi.php?ac=photo&tid=341&from=timeline&isappinstalled=0")
qr.make(fit=True) img = qr.make_image()
img = img.convert("RGBA") icon = Image.open("pvg.png") img_w, img_h = img.size
factor = 4
size_w = int(img_w / factor)
size_h = int(img_h / factor) icon_w, icon_h = icon.size
if icon_w > size_w:
icon_w = size_w
if icon_h > size_h:
icon_h = size_h
icon = icon.resize((icon_w, icon_h), Image.ANTIALIAS) w = int((img_w - icon_w) / 2)
h = int((img_h - icon_h) / 2)
img.paste(icon, (w, h), icon) img.save("dhqme_qrcode.png")

结果:

最新文章

  1. xamarin绑定原生库的一些坑
  2. The .NET of Tomorrow
  3. 前端小知识点---html换行被解析为空格的相关知识
  4. fasicon.js (无二维码版,如需要js创建二维码版本可联系我:770959294@qq.com)
  5. STM32重映射(PinRemap)的使用,注意!
  6. Scrum Meeting 3-20151203
  7. svn 403 Forbidden
  8. mac os x用macport安装redis
  9. C#设计模式——单件模式(Singleton Pattern)
  10. 【iBoard电子学堂】【iCore双核心板】资料光盘A盘更新,版本号为A6
  11. Oracle 手动收集统计信息
  12. poj 1236 Network of Schools【强连通求孤立强连通分支个数&&最少加多少条边使其成为强连通图】
  13. SQL Developer 4.1.3
  14. 学习web前端技术的笔记,仅供自己查阅备忘,移动对font-size的控制(并非原创)
  15. sshpass 实现shell脚本直接加载密登录服务器
  16. nginx php上传大文件的设置(php-fpm)
  17. DOM事件阶段以及事件捕获与事件冒泡先后执行顺序
  18. [ 转载 ] Android JNI(一)——NDK与JNI基础
  19. VMware的存储野心(下):虚拟卷和闪存缓存
  20. STN1110 Multiprotocol OBD to UART Interpreter

热门文章

  1. Android setVisibility(View.GONE)无效的问题及原因分析
  2. ReactiveCocoa 响应式函数编程
  3. 使用Azure CDN更快速的交付内容
  4. Spring Boot: Spring Starter Project
  5. 忘记Centos7.2下root用户密码后的处理方式
  6. 异步 Thread
  7. codevs 4165 ​高精度求阶乘
  8. spring (由Rod Johnson创建的一个开源框架)
  9. WPF知识点全攻略03- XAML
  10. CPP-基础:内部函数应该在当前源文件中说明和定义