【问题标题】:How can I add a picture frame/border to multiple images from the same folder in python?如何将相框/边框添加到 python 中同一文件夹中的多个图像?
【发布时间】:2018-06-25 21:19:29
【问题描述】:

enter link description here

我需要能够对同一文件夹中的多个图像执行此操作。

【问题讨论】:

    标签: python mask


    【解决方案1】:

    你可以用这个:

    import glob, os
    os.chdir("/")
    for infile in glob.glob("*.jpg"):
        file, ext = os.path.splitext(infile)
        im = Image.open(infile)
        add_border(im)
    
    import Image
    def add_border(im):
        old_im = im
        old_size = old_im.size
    
        new_size = (800, 800)
        new_im = Image.new("RGB", new_size)   ## luckily, this is already black!
        new_im.paste(old_im, ((new_size[0]-old_size[0])/2,(new_size[1]-old_size[1])/2))
        new_im.show()
        # new_im.save('someimage.jpg')
    

    @学分:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-17
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      • 2016-07-15
      • 2020-02-26
      • 2020-02-13
      相关资源
      最近更新 更多