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


    最近在做一个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)

  • 相关阅读:
    实操记录之-----Ant Design of Vue 增强版动态合并单元格,自动根据数据进行合并,可自定义横纵向合并
    实操好用~~~~~antd 中 Table表格动态合并~~~
    超级容易理解的函数节流(throttle)
    Flask框架
    Celery框架
    redis数据库如何用Django框架缓存数据
    luffyapi项目 --短信认证的基本操作
    DRF之Jwt 实现自定义和DRF小组件及django-filter插件的使用
    Auth主件的(RBAC) 六表
    DRF之三大认证
  • 原文地址:https://www.cnblogs.com/rixiang/p/10394756.html
Copyright © 2020-2023  润新知