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 ...
随机推荐
- Java开发WebService的几种方法--转载
webservice的应用已经越来越广泛了,下面介绍几种在Java体系中开发webservice的方式,相当于做个记录. 1.Axis2 Axis是apache下一个开源的webservice开发组件 ...
- 后缀树系列一:概念以及实现原理( the Ukkonen algorithm)
首先说明一下后缀树系列一共会有三篇文章,本文先介绍基本概念以及如何线性时间内构件后缀树,第二篇文章会详细介绍怎么实现后缀树(包含实现代码),第三篇会着重谈一谈后缀树的应用. 本文分为三个部分, 首先介 ...
- Activity学习(一)——状态转变
(转自:http://blog.csdn.net/flowingflying/article/details/6415323) Android很大的应用场景是手机,有一些应用具有特别的优先级别,例如电 ...
- DevExpress licenses.licx 问题
在DevExpress ( 当然并不范指DevExpress,很多收费软件都是这样的)中,licenses.licx 是用户许可证书文件,当我们使用某些ActiveX(是Microsoft对于一系列策 ...
- (转)Android学习进阶路线导航线路(Android源码分享)
转载请注明出处:http://blog.csdn.net/qinjuning 前言:公司最近来了很多应届实习生,看着他们充满信心但略带稚气的脸庞上,想到了去年的自己,那是的我是不是也和 现在的他们一 ...
- POJ 3150 Cellular Automaton(矩阵乘法+二分)
题目链接 题意 : 给出n个数形成环形,一次转化就是将每一个数前后的d个数字的和对m取余,然后作为这个数,问进行k次转化后,数组变成什么. 思路 :下述来自here 首先来看一下Sample里的第一组 ...
- hdu2023 求平均成绩 ~~很闲~~~
#include<iostream> #include<stdio.h> #include<math.h> #include<string.h> #in ...
- Why you have so few friends?
Why you have so few friends?十个原因告诉你:为什么你的朋友那么少1. You Complain A Lot 你总是抱怨 If you’re constantly compl ...
- 一行代码设置TLabel.Caption的前世今生
第零步,测试代码: procedure TForm1.Button1Click(Sender: TObject); begin Label1.Caption := 'Hello World'; end ...
- c#实现打印功能,可以设置纸张大小,字体和颜色等
/// <summary> /// 打印的按钮 /// </summary> /// <param name="sender"></par ...