python表情包加工脚本

作者: gavin 分类: AI 发布时间: 2023-09-19 11:39

1、切图脚本

import os
from PIL import Image

# 创建一个名为"finish"的目录,用于保存切割后的小图
if not os.path.exists("finish"):
    os.mkdir("finish")

# 获取当前目录下的所有图片文件
image_files = [filename for filename in os.listdir() if filename.endswith((".jpg", ".jpeg", ".png"))]

# 循环处理每个图片文件
for i, image_file in enumerate(image_files):
    # 打开图片
    img = Image.open(image_file)

    # 获取图片的宽度和高度
    width, height = img.size

    # 计算每个小图的宽度和高度
    small_width = width // 2
    small_height = height // 2

    # 切割图片成四个小图
    small_images = [
        img.crop((0, 0, small_width, small_height)),
        img.crop((small_width, 0, width, small_height)),
        img.crop((0, small_height, small_width, height)),
        img.crop((small_width, small_height, width, height))
    ]

    # 保存小图到"finish"目录中,以数字编号命名
    for j, small_img in enumerate(small_images):
        small_img.save(f"finish/{i + 1}_{j + 1}.png")

print("切割完成并保存在'finish'目录中。")

2、组装prompt

# 读取前段.txt中的头部内容
with open("前段.txt", "r", encoding="utf-8") as f:
    前段内容 = f.read()

# 读取后段.txt中的尾部内容
with open("后段.txt", "r", encoding="utf-8") as f:
    后段内容 = f.read()

# 读取中段.txt中的所有prompt
with open("中段.txt", "r", encoding="utf-8") as f:
    所有prompt = f.readlines()

# 将每个prompt与头部和尾部拼接后写入完成.txt
with open("完成.txt", "w", encoding="utf-8") as f:
    for prompt in 所有prompt:
        完整prompt = 前段内容 + " " + prompt.strip() + " " + 后段内容 + "\n"
        f.write(完整prompt)

前段.txt

/imagine prompt: https://i.imgur.com/LVC5w93.png

中段.txt

Expression: Shy smile, Action: Hiding behind a flower, Attire: Floral dress, Coat: Orange Tabby, Breed: Bengal
Expression: Cool smirk, Action: Skateboarding, Attire: Streetwear, Coat: Gray, Breed: American Shorthair
Expression: Playful grin, Action: Playing with a ball of yarn, Attire: Sweater, Coat: White, Breed: Turkish Angora
Expression: Blushing smile, Action: Holding a heart, Attire: Valentine's Day outfit, Coat: Pink, Breed: Persian
Expression: Surprised expression, Action: Popping out of a box, Attire: Party hat and bow tie, Coat: Tortoiseshell, Breed: Exotic Shorthair
Expression: Smiling with heart eyes, Action: Holding a bouquet of flowers, Attire: Floral dress, Coat: White and gray, Breed: British Shorthair
Expression: Angry scowl, Action: Hissing, Attire: Spiky collar, Coat: Black, Breed: Bombay
Expression: Laughing out loud, Action: Rolling on the floor, Attire: Comfy pajamas, Coat: Orange and white, Breed: Tabby
Expression: Skeptical look, Action: Tilting head, Attire: Bow tie, Coat: Gray and white, Breed: Chartreux
Expression: Sleeping soundly, Action: Tucked into bed, Attire: Pajamas and sleep mask, Coat: Cream, Breed: Siamese
Expression: Inquisitive expression, Action: Peeking around a corner, Attire: Explorer hat and backpack, Coat: Tortoiseshell, Breed: Maine Coon
Expression: Sassy smirk, Action: Playing with a toy mouse, Attire: Tutu skirt, Coat: Calico, Breed: Scottish Fold
Expression: Curious look, Action: Poking head out of a bag, Attire: Shopping bag, Coat: Gray and white, Breed: Russian Blue
Expression: Stressed out expression, Action: Covered in paperwork, Attire: Business suit, Coat: Black and white, Breed: American Bobtail
Expression: Disgusted expression, Action: Stepping in a hairball, Attire: Shower cap and robe, Coat: Orange and white, Breed: Himalayan
Expression: Mischievous grin, Action: Knocking over a vase, Attire: Bow tie, Coat: Gray and white, Breed: Tonkinese
Expression: Bored expression, Action: Laying in a sunbeam, Attire: Sunglasses, Coat: Black, Breed: Bombay
Expression: Confused expression, Action: Looking at a Rubik's cube, Attire: Geek glasses, Coat: Gray, Breed: British Shorthair
Expression: Flirty wink, Action: Blowing a kiss, Attire: Red dress, Coat: White, Breed: Siamese
Expression: Fierce snarl, Action: Clawing a scratching post, Attire: Leather collar, Coat: Black and white, Breed: Bengal
Expression: Grumpy frown, Action: Refusing to come out of a box, Attire: Birthday hat, Coat: Gray, Breed: Persian

后段.txt

, digital drawing cartoon sticker, is a cat, with cat ears, Ghibli, image black border Color, baseball cap, fat, fluffy, full body, flat texture cartoon style, 2D --niji --v 4 --q 5