importImage,ImageDraw,ImageFont, os, glob

list = glob.glob('*.jpg')for infile in list:print infile
file, ext = os.path.splitext(infile)
outname = file +"_test.jpg"print outname
im =Image.open(infile)
d =ImageDraw.Draw(im)
f =ImageFont.truetype("Arial.ttf",16)
d.text((4,0), file, font=f)
im.save(outname)

It prints out the name of the file, so the file is there - so why can't it open it?

The file exists, but I get the following error:

Is there an easier way to add a caption to the bottom of the image?

Thanks to the help of Nick & Manu pointing me in the right dierction, I worked out a solution that works:


importImage,ImageDraw,ImageFontfrom PIL importImageimport glob, os
importTkinterimportImageTkimport fnmatch list = glob.glob('*.jpg') cnt =0for infile in list:
cnt +=1print infile
file, ext = os.path.splitext(infile)
outname = file +"_test.jpg"print outname
#im = Image.open(infile)
im =Image.open(open(infile,'rb'))
d =ImageDraw.Draw(im)
f =ImageFont.truetype("c:/windows/fonts/arial.ttf",200)
x =10
y =550
d.text((x, y), str(cnt), font=f)
im.save(outname)print"==========="

Need to add a caption to a jpg, python can't find the image的更多相关文章

  1. 【LeetCode】 258. Add Digits 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:减1模9 方法三:直接模9 日 ...

  2. Add Two Numbers(from leetcode python 链表)

    给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将两数相加返回一个新的链表. 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 示例: 输入:(2 -& ...

  3. Django补充及初识Ajax

    Django创建一对多表结构 首先现在models.py中写如下代码: from django.db import models # Create your models here. class Bu ...

  4. delphi---控件使用

    1.TBitBtn控件 属性:Glyph,指定要显示的位图:    Layout ,设置位图在按钮的位置:Kind,要想用自设位图,这个属性要设置bkCustom; 2.TTreeView TTree ...

  5. Delphi Excel 操作大全

    Delphi Excel 操作大全 (一) 使用动态创建的方法首先创建 Excel 对象,使用ComObj:var ExcelApp: Variant;ExcelApp := CreateOleObj ...

  6. LaTeX插入图片方法 Inserting Images

    Inserting Images Images are essential elements in most of the scientific documents. LATEX provides s ...

  7. SQLAlchemy一对多总结

    1.SQLAlchemy之一对多关系 1.1 创建单表 class Test(Base): __tablename__ = 'user' nid = Colume(Integer,primary_ke ...

  8. Python(SQLAlchemy-ORM)模块之mysql操作

    一.SQLAlchemy简单介绍 SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数 ...

  9. Django web 基础

    一.Django概述 Django大而全; 创建Django工程:django-admin startproject sitename 创建django之后生成的目录结构如下: Project Pro ...

随机推荐

  1. ***iOS开发中@selector的理解与应用

    @selector 是什么? 1一种类型 SEL2代表你要发送的消息(方法), 跟字符串有点像, 也可以互转.: NSSelectorFromString() / NSSelectorFromStri ...

  2. WCF分布式开发步步为赢(11):WCF流处理(Streaming)机制

    WSE3.0框架提供了数据优化传输机制,WSE3.0构建Web服务安全(4):MTOM消息传输优化和文件上传.下载 疑问里进行了介绍.WCF同样也提供了流操作来支持大数据对象的传输和处理优化机制,今天 ...

  3. centOS学习part2:安装JDK及tomcat

    0 上一篇(http://www.cnblogs.com/souvenir/p/3875424.html)给大家介绍了centOS操作系统的安装,接下来我们来介绍centOS常用软件的安装以及配置,希 ...

  4. 【PSR规范专题(4)】PSR-3 日志接口规范

    本文转自:https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-3-logger-interface-cn.md 本文制定了日志类库的通用接口规范. ...

  5. MotionEvent

    getAction() returns a pointer id and an event (i.e., up, down, move) information. getActionMasked()  ...

  6. QT中可以用QProgressBar或着QProgressDialog来实现进度条

    QProgressBar的使用 首先在designer中拖一个按钮和进度条部件,按下面初始化 //补充:下面两句写在MainWindow的构造函数里进行初始化 ui->progressBar-& ...

  7. QT visual stuido 集成插件不能打开ui文件的解决方法(去掉xml的UTF8标记)

    QT visual stuido 集成插件不能打开ui文件的解决方法 visual studio里不能打开这个ui文件,出现warning等解决方法是:于是将<?xml version=&quo ...

  8. 编译FreePascal和Lazarus

    一,准备目录假设我们准备将整个FreePascal环境安装到D盘的fpc目录下,那么我们需要创建以下几个目录:d:\fpc_svn\bind:\laz_svn二,准备环境1,安装SVN客户端Torto ...

  9. [Spring Boot 系列] 集成maven和Spring boot的profile功能

    由于项目的需要, 今天给spirng boot项目添加了profile功能.再网上搜索了一圈,也没有找到满意的参考资料,其实配置并不难,就是没有一个one stop(一站式)讲解的地方,所以有了写这篇 ...

  10. c# 浏览器区别

    c#   浏览器区别 思路:浏览器本身独有的属性来区别: 1.window对象的属性来区别: window.attachEvent               IEwindow.addEventLis ...