import numpy as np
import os
def add_logo(save_dir='.\mainpic_logo_new',resize_radio=1,logo_dis=(76,72)):
logo_img = Image.open(r"D:\\BaiduSyncdisk\\WORK\Honor\\国际站运营\\logo.png")
print(logo_img.size)
logo_img = logo_img.resize((int(403*resize_radio), int(52*resize_radio)),Image.ANTIALIAS)
print(logo_img.size)
# logo_img.show()
img_path= 'D:\\BaiduSyncdisk\\WORK\\Honor\\国际站运营\\主图加LOGO\\主图加LOGO'
save_dir = save_dir
for pic_file in os.listdir(img_path):
# if not os.path.exists(os.path.join(save_dir,pic_file)):
save_pic_path = os.path.join(save_dir,pic_file)
os.makedirs(save_pic_path,exist_ok=True)
print(save_pic_path)
par_path = os.path.join(img_path,pic_file)
for pic in os.listdir(par_path):
try:
pic_img = os.path.join(par_path,pic)
img1 = Image.open(pic_img)
print(np.array(img1).shape)
img1.paste(logo_img, logo_dis, mask = logo_img)
print(os.path.join(save_pic_path,pic))
img1.save(os.path.join(save_pic_path,pic))
except:
continue
if __name__ == "__main__":
radio_size_list = [1,0.9,0.8,0.7,0.6]
logo_dis_list = [(76,72),(66,62),(58,56),(49,46),(39,36)]
for radio_size in radio_size_list:
for logo_dis in logo_dis_list:
save_dir = f".\mainpic_logo_new_{radio_size}_{logo_dis}"
add_logo(save_dir,radio_size,logo_dis)