最近在做一个android的电台,此android程序要访问自己服务器上的歌曲文件,包括图片。这些文件要自己手动上传。

每天十首歌,需要二十个图片(一个大图450*450、一个小图140*140)。

特定的名称、和分辨率。

手动做这些还是要浪费很多时间的,于是我就选择写个python脚本。

用py2exe工具转化为exe程序。

这样我只需要下好十张图片,(0.jpg到9.jpg)然后运行这一工具,就自动生成二十张图片。

# -*- coding: utf-8 -*-
from PIL import Image infile = '0.jpg'
outfile = '0-origin.jpg'
outfile2 = '0-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '1.jpg'
outfile = '1-origin.jpg'
outfile2 = '1-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '2.jpg'
outfile = '2-origin.jpg'
outfile2 = '2-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '3.jpg'
outfile = '3-origin.jpg'
outfile2 = '3-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '4.jpg'
outfile = '4-origin.jpg'
outfile2 = '4-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '5.jpg'
outfile = '5-origin.jpg'
outfile2 = '5-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '6.jpg'
outfile = '6-origin.jpg'
outfile2 = '6-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '7.jpg'
outfile = '7-origin.jpg'
outfile2 = '7-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '8.jpg'
outfile = '8-origin.jpg'
outfile2 = '8-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2) infile = '9.jpg'
outfile = '9-origin.jpg'
outfile2 = '9-thumbnail.jpg'
im = Image.open(infile)
out = im.resize((450,450),Image.ANTIALIAS)
out.save(outfile) out = im.resize((140,140),Image.ANTIALIAS)
out.save(outfile2)

python脚本,重新设置图片大小-LMLPHP

05-28 16:39