Need to add a caption to a jpg, python can't find the image
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的更多相关文章
- 【LeetCode】 258. Add Digits 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:减1模9 方法三:直接模9 日 ...
- Add Two Numbers(from leetcode python 链表)
给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将两数相加返回一个新的链表. 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 示例: 输入:(2 -& ...
- Django补充及初识Ajax
Django创建一对多表结构 首先现在models.py中写如下代码: from django.db import models # Create your models here. class Bu ...
- delphi---控件使用
1.TBitBtn控件 属性:Glyph,指定要显示的位图: Layout ,设置位图在按钮的位置:Kind,要想用自设位图,这个属性要设置bkCustom; 2.TTreeView TTree ...
- Delphi Excel 操作大全
Delphi Excel 操作大全 (一) 使用动态创建的方法首先创建 Excel 对象,使用ComObj:var ExcelApp: Variant;ExcelApp := CreateOleObj ...
- LaTeX插入图片方法 Inserting Images
Inserting Images Images are essential elements in most of the scientific documents. LATEX provides s ...
- SQLAlchemy一对多总结
1.SQLAlchemy之一对多关系 1.1 创建单表 class Test(Base): __tablename__ = 'user' nid = Colume(Integer,primary_ke ...
- Python(SQLAlchemy-ORM)模块之mysql操作
一.SQLAlchemy简单介绍 SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数 ...
- Django web 基础
一.Django概述 Django大而全; 创建Django工程:django-admin startproject sitename 创建django之后生成的目录结构如下: Project Pro ...
随机推荐
- 国内银行CNAPS CODE 查询
原地址:http://weekend.blog.163.com/blog/static/746895820127961346724/ 全国各地,无论哪个银行,无论什么分行,所有的CNAPS CODE都 ...
- vi/vim使用指北 ---- Beyond the Basic
更多的组合命令 [number]-[command]-[test object] number: 数字 comand: c,d,y (修改,删除,复制) test object: 移动光标的命 ...
- http协议本身能获取客户端Mac地址问题
http 位于网络应用程 应用层 会话层 表示层 传输层 网络层 数据链路层 物理层 数据在最高层开始传输 没经历下面一层加一层的头,然后传入目的电脑再进行一层层的解刨,所以http本来没有mac而接 ...
- [网页设计]Ajax、Comet与Websocket--转
从http协议说起 1996年IETF HTTP工作组发布了HTTP协议的1.0版本 ,到现在普遍使用的版本1.1,HTTP协议经历了17 年的发展.这种分布式.无状态.基于TCP的请求/响应式.在 ...
- 快速创建maven 工程:simple java工程,webapp
http://www.cnblogs.com/buhaiqing/archive/2012/11/04/2754187.html 会从maven的Repository里查找所有支持的arche typ ...
- C#格式化输出
double a = 12354.365; Console.WriteLine(string.Format("{0:f4}", a)); 输出a的四位小数
- ios开发--第三方整理
一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://github. ...
- Centos环境下部署游戏服务器-自动化
计算机是没有智力的,只会接受指令,运行指令,得出结果.因此就算你让它重复做一件事多少次,它也学不会自动去做这件事.对于重复繁琐的事情,做为一个懒惰的程序员,必须告诉机器去做这件事情,然后就行了,而不是 ...
- [转]ArcGIS计算图斑的四邻坐标(XMin,XMax,YMin,YMax)
1.背景: 在国土,调查等行业业务里面经常有需要计算某个图斑的四邻坐标,即xmax,xmin,ymin,ymax;也就是常说的MBR(最小外包矩形),本教程演示如何计算一个shapefile文件上的图 ...
- 1、Hibernate之生成SessionFactory源码追踪
Hibernate的所有session都是由sessionFactory来生成的,那么,sessionFactory是怎么得来的呢?它与我们配置的xxx.cfg.xml文件以及xxx.hbm.xml文 ...