zoukankan      html  css  js  c++  java
  • 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: enter image description here

    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:


    import
    Image,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"==========="
  • 相关阅读:
    Matlab 画图
    OfferCome-0531
    OfferCome--0528
    剑指offer(2)
    剑指offer(1)
    MySQL的自增主键
    java Junit 测试
    sql 注入问题
    Facebook Libra
    markdown的博客
  • 原文地址:https://www.cnblogs.com/jacker1979/p/3761805.html
Copyright © 2011-2022 走看看