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. jvm 之 国际酒店 6月25日上线内存溢出原因

    6月25日OMS,Ihotel上线成功后执行了一个批处理,SOA报警提示某一台IHOTEL机器调用OMS失败率大于阀值,登录这个机器后发现这台机器CPU使用率处于80%以上,调用OMS有的时候超过5秒 ...

  2. 全国DNS汇总

    全国DNS汇总 来路不明的DNS服务器可能导致你的帐号密码轻易被盗,请谨慎使用!在中国大陆,最科学的方法是将首选DNS服务器设置为114.114.114.114,备用DNS服务器设置为当地电信运营商的 ...

  3. hdu 4389 X mod f(x) 数位DP

    思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...

  4. Android 注入详解

    Android下的注入的效果是类似于Windows下的dll注入,关于Windows下面的注入可以参考这篇文章Windows注入术.而Android一般处理器是arm架构,内核是基于linux,因此进 ...

  5. Maven的配置文件pom.xml

    Maven的配置文件pom.xml 简介: 什么是POM? POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml. ...

  6. oracle连接数据

    1.源代码 string connString = "User ID=scott;Password=yanhong;Data Source=(DESCRIPTION = (ADDRESS_L ...

  7. MongoDB (八) MongoDB 文档操作

    一. MongoDB 插入文档 insert() 方法 要插入数据到 MongoDB 集合,需要使用 MongoDB 的  insert() 或 save() 方法. 语法 insert() 命令的基 ...

  8. hive-学习笔记

    1.hive模糊搜索表  show tables like '*name*'; 2.查看表结构信息  desc formatted table_name;  desc table_name; 3.查看 ...

  9. android 矩阵处理类:Matrix

    在Android中,对图片的处理需要使用到Matrix类,Matrix是一个3 x 3的矩阵,他对图片的处理分为四个基本类型: 1.Translate 2.Scale 3.Rotate 4.Skew ...

  10. Cornerstone问题

    // Cornerstone锁 Cornerstone locks a working copy whenever it performs operations suchs as commits, u ...