zoukankan      html  css  js  c++  java
  • python 根据大图片生成各种规格图片 生成ios需要的各个规格的icon

    PIL库要安装,直接使用pip安装:

    pip install pillow

    可能会报错,我python是3.x版本的,好像2.x版本的没有pip(需要单独安装)

    3.x版本的安装如果报一堆错出来,它会提示需先更新pip版本(命令也提示出来了,照着输入执行即可):

    `pip install --upgrade pip`

    然后再安装插件: `pip install pillow`

    python脚本代码:

    #!/usr/bin/python
    # -*- coding:utf-8 -*-
    
    # 生成ios需要的各个规格的icon(通过1024*1024的图片)
    
    from PIL import Image
    
    infile = './expand_iOSicon_by1024/2.png'  # input('Please enter the image path: ')
    outPath = './expand_iOSicon_by1024/2'  # input('Please enter the export path: ')
    print('infile:' + infile)
    img = Image.open(infile)
    (w, h) = img.size
    print('originW:' + str(w) + ',originH:' + str(h))
    
    arr = [40, 60, 58, 87, 80, 120, 180]
    for index in arr:
        newW = index
        newH = int(h * newW / w)
        print('h:{},newW:{},w:{},newH:{}'.format(h, newW, w, newH))
        outfile = outPath + '/' + 'Icon-' + str(index) + '.png'
        out = img.resize((newW, newH),
                         Image.ANTIALIAS)  # resize image with high-quality
        out.save(outfile)
        print('output file ' + 'Icon-' + str(index) + '.png...')
    
    print('Export all ICONS finished...')
  • 相关阅读:
    apache 错误日志
    搭建服务器
    vim配置
    临时表增加查询速度
    如何清空$_POST or $_GET
    hdu 2084
    快速幂
    zjut 1176
    rwkj 1091
    zjut 1090 --------同余定理的应用
  • 原文地址:https://www.cnblogs.com/Denny_Yang/p/14155324.html
Copyright © 2011-2022 走看看