• python图片云


    Python 小工具 把图片拼接成任意大小新图片 代码比较简单 看注释就好

    # -*- coding:utf-8 -*-
    #图片拼接
    import PIL.Image as Image
    import os, sys
    file_dir = "C:\UsersAdministratorDesktopzhihuzhihu_userimages\full"
    def g():
        for root, dirs, files in os.walk(file_dir):
            for file in files:
                yield os.path.join(root,file)
    gfile=g()
    import os
    from PIL import Image
    '''
    把当前目录下的10*10张jpeg格式图片拼接成一张大图片
    '''
    :# 图片压缩后的大小
    width_i = 100
    height_i = 100
    :# 每行每列显示图片数量
    line_max = 10
    row_max = 10
    :# 参数初始化
    all_path = []
    num = 0
    pic_max = line_max * row_max
    dirName = os.getcwd()
    toImage = Image.new('RGBA', (width_i * line_max, height_i * row_max))
    for i in range(0, row_max):
        for j in range(0, line_max):
            pic_fole_head = Image.open(next(gfile))
            width, height = pic_fole_head.size
            tmppic = pic_fole_head.resize((width_i, height_i))
            loc = (int(i % line_max * width_i), int(j % line_max * height_i))
            # print("第" + str(num) + "存放位置" + str(loc))
            toImage.paste(tmppic, loc)
            num = num + 1
    print(toImage.size)
    toImage.save("C:\UsersAdministratorDesktopmerged.png")
    

    git https://github.com/tongchengbin/pythontools/blob/master/imgCloud.py

  • 相关阅读:
    新的起点,虽半步即天涯
    自定义函数
    冒泡排序 数字去重
    for 循环练习题
    for 循环练习题(2)
    for 循环 乘法口诀表
    js基础标签用法
    网页格式布局 流式布局
    样式表属性
    框架
  • 原文地址:https://www.cnblogs.com/tongchengbin/p/8404885.html
Copyright © 2020-2023  润新知