zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Python-异常处理机制
    递归函数——斐波那契数列j
    函数及相关操作
    字符串及相关操作
    集合及相关操作
    元组
    字典
    列表元素增删改排操作
    multiprocessing模块简单应用
    02 for循环创建进程
  • 原文地址:https://www.cnblogs.com/tongchengbin/p/8404885.html
Copyright © 2011-2022 走看看