python 图片上下左右批量添加像素
2020-05-15 本文已影响0人
九月_adhoc
图片上下左右添加像素,做项目的时候ui切图不标准,有些地方自己要弄到所以出了下面这个脚本
注意 安装pil是的
pip install pillow
import os
from PIL import Image
def all_add():
fpath = "/Users/hc-101/Desktop/emptyicon"
img_suffix_list = ["png","jpg","bmp"]
paths = os.listdir(fpath)
for i in os.listdir(fpath):
if i.split('.')[-1] in img_suffix_list:
img_path = fpath + '/' + i
save_path = fpath + '/end/' + i
print(img_path)
img_water_mark(img_path,save_path)
def img_water_mark(img_file,save_path):
im = Image.open(img_file)
im = im.resize((60,60*im.size[1]/im.size[0]))
space = 10
#新建一个图像背景
layer=Image.new('RGBA', (im.size[0]+space*2,im.size[1]+space*2), "#FF000000")
layer.paste(im, (space,space))
layer.save(save_path,'png')
layer.show()
def add_num():
im = Image.open("/Users/hc-101/Desktop/emptyicon/a.png")
#新建一个图像背景
layer=Image.new('RGBA', (im.size[0]+40,im.size[1]+40), "#FF000000")
layer.save('/Users/hc-101/Desktop/emptyicon/end/result1.png','png')
layer.show()
layer.paste(im, (20,20))
layer.show()
# out=Image.composite(layer,im,layer)
# out.save('/Users/hc-101/Desktop/emptyicon/result.png','png')
# out.show()
if __name__ == '__main__':
# add_num()
all_add()