【教学类-36-12-01】20240302儿童对称正脸图(一)4图右脸+4图左脸(中班《幼儿园里朋友多》)(midjounery-v 5.1 Python图片切割)

作品展示:

f8d8b601efca439cbf909b97949a8a7f.png

5cff602813b44019b28d10e26b1f99a0.png

背景需求:

中班《幼儿园里朋友多》操作材料包——画对称脸

255c7e46a4054201b502afedf59c64d3.jpeg

尝试用midjounery获得更多幼儿正脸图形,切割一半,制作相似的学具

一、MJ获取简笔画图案

风变编程——MJ

第1个关键词

Children's face, front, simple stroke, cartoon, black and white outline, uncolored,--niji 5

儿童脸,正面,简单笔画,卡通,黑白轮廓,未着色

f737795a55e845febb3136455ba01de3.png

第2个关键词

The face of a 5-year-old girl, front, simple stroke, cartoon, black and white outline, uncolored --niji 5

5岁女孩的脸,正面,简单的笔画,卡通,黑白轮廓,未上色

f63c77eef54e4559b2165b9978962787.png

第3个关键词

The face of a 5-year-old girl is frontal, symmetrical, with uncolored hair, simple strokes, cartoonish, black and white contours, uncolored --niji 5

一个5岁女孩的脸是正面的,对称的,没有颜色的头发,简单的笔触,卡通的,黑白的轮廓,没有颜色

c75a17816f224133a66fc162a013b762.png

第4个关键词

The face of a 5-year-old girl is frontal, symmetrical, with simple lines, simple strokes, cartoonish, black and white contours, uncolored, and hair with only contours --niji 5

一个5岁女孩的脸是正面的,对称的,线条简单,笔画简单,卡通的,黑白的轮廓,没有颜色,头发只有轮廓

06c6c98abda34140aec5b21115493721.png

第5个关键词(更换“加粗边线”关键词)

illustration for toddlers coloring books, line drawing, no background, no colors, black and white comic line art for: the face of a cute 5-years-old girl is frontal, symmetrical, , empty background, thick outline, crisp lines, vector lines. simple, big, cute, --v 5.1 --q 5  --s 420 --ar 1:1

幼儿插图涂色书籍,白描,无背景,无颜色,黑白漫画线条艺术:一个可爱的5岁女孩的脸是正面的,对称的,空的背景,粗的轮廓,清晰的线条,矢量线。简单,大,可爱,--q 5-s 420--ar 1:1

d57bc07d4d174cebb418b40758de2f22.png

第6个关键词

illustration for toddlers coloring books, line drawing, no background, no colors, black and white comic line art for: the frontal face of a cute 5-years-old girl ,hair style is symmetrical, , empty background, thick outline, crisp lines, vector lines. simple, big, cute,  --v 5.1 --q 5  --s 420 --ar 1:1

幼儿涂色书插图,白描,无背景,无颜色,黑白漫画线条艺术用于:一个可爱的5岁女孩的正面,发型对称,背景空,轮廓粗,线条清晰,矢量线。简单,大,可爱,--q 5-s 420--ar 1:1

40183f3f5b1a47d296d4df29dbe0caaf.png

第7个关键词

illustration for toddlers coloring books, line drawing, no background, no colors, black and white comic line art for: the frontal face of a cute 5-years-old girl ,Different symmetrical hairstyles, different facial features, empty background, thick outline, crisp lines, vector lines. simple, big, cute,  --v 5.1 --q 5  --s 420 --ar 1:1

幼儿涂色书插图,白描,无背景,无颜色,黑白漫画线条艺术用于:一个可爱的5岁女孩的正面,不同的对称发型,不同的面部特征,空背景,粗轮廓,清晰的线条,矢量线。简单,大,可爱,--q 5-s 420--ar 1:1

98a7ca5941624517bd8b9656c9186cd7.png

第8个关键词

illustration for toddlers coloring books, line drawing, no background, no colors, black and white comic line art for: the frontal face of a cute 5-years-old girl ,Different symmetrical hairstyles, Different symmetrical hairstyles, different eye shapes, different nose shapes, and different mouth shapes, empty background, thick outline, crisp lines, vector lines. simple, big, cute,  --v 5.1 --q 5  --s 420 --ar 1:1

幼儿涂色书插图,白描,无背景,无颜色,黑白漫画线条艺术:一个可爱的5岁女孩的正面,不同的对称发型,不同的不对称发型,不同眼睛形状,不同的鼻子形状,和不同的嘴形状,空背景,粗轮廓,清晰的线条,矢量线。简单,大,可爱,--q 5-s 420--ar 1:1

dc1e724c68a9439d92a08e484a0c4464.png

第9个关键词

illustration for toddlers coloring books, line drawing, no background, no colors, black and white comic line art for: the frontal face of a cute 5-years-old child, ,Different symmetrical hairstyles, Different symmetrical hairstyles, different eye shapes, different nose shapes, and different mouth shapes, empty background, thick outline, crisp lines, vector lines. simple, big, cute, --v 5.1  --q 5  --s 420 --ar 1:1

幼儿涂色书插图,白描,无背景,无颜色,黑白漫画线条艺术:一个可爱的5岁孩子的正面,,不同的对称发型,不同的不对称发型,不同眼睛形状,不同的鼻子形状,和不同的嘴形状,空背景,粗轮廓,清晰的线条,矢量线。简单,大,可爱,--q 5-s 420--ar 1:1

00f0e781929344ad9f2cb015e940c10b.png

3e66c9ed9c104071b06b578ab6f3d442.png第10个关键词——改成了children(很多孩子)

illustration for toddlers coloring books, line drawing, no background, no colors, black and white comic line art for: the frontal face of a cute 5-years-old children, ,Different symmetrical hairstyles, Different symmetrical hairstyles, different eye shapes, different nose shapes, and different mouth shapes, empty background, thick outline, crisp lines, vector lines. simple, big, cute, --v 5.1  --q 5  --s 420 --ar 1:1

幼儿涂色书插图,白描,无背景,无颜色,黑白漫画线条艺术用于:一个可爱的5岁儿童的正面,,不同的对称发型,不同的不对称发型,不同眼睛形状,不同的鼻子形状,和不同的嘴形状,空背景,粗轮廓,清晰的线条,矢量线。简单,大,可爱,--q 5-s 420--ar 1:1

23f5d0622acb4ce98a92a263cb0b3922.png

就是切割起来不一定正好3宫格、4宫格包含全。

二、下载11张图片

6ae605da455642c2bed0710750b0c46d.png

e792d2f789604b23be2bff58f5ed3d13.png

三、先切割成4张图


# 参考网址:https://blog.csdn.net/weixin_42182534/article/details/125773141?ops_request_misc=&request_id=&biz_id=102&utm_term=python%E6%88%AA%E5%8F%96%E5%9B%BE%E7%89%87%E7%9A%84%E4%B8%80%E9%83%A8%E5%88%86&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-125773141.nonecase&spm=1018.2226.3001.4187

'''

功能:对称脸图片切割2048*2048,2*2 第一步切成4张图
作者:阿夏
时间:2024年3月2日 19:51
'''

import os
import os.path

from PIL import Image

long=2048
wide=2048

small_long=2
small_wide=2
# 目前图片都是2*2,3*3排列


z=0
longall=[]
longall.append(z)
for l in range(1,small_long+1):
    ll=float(long/small_long*l)
    longall.append(ll)
print(longall)
# 右侧边的所有参数 长/X
# [0, 512, 1024, 1536, 2048]


wideall=[]
wideall.append(z)
for w in range(1,small_wide+1):
    ww=float(wide/small_wide*w)    
    wideall.append(ww)
print(wideall)
# 下边的所有参数 宽/X
# [0, 682.6666666666666, 1365.3333333333333, 2048.0]


pic=[]
for x in range(0,small_wide):
    for y in range(0,small_long):
        z1=longall[y]
        z2=wideall[x]
        z3=longall[y+1]
        z4=wideall[x+1]
        pic.append(z1)
        pic.append(z2)
        pic.append(z3)
        pic.append(z4)
print(len(pic))

four=r'C:\Users\jg2yXRZ\OneDrive\桌面\儿童正脸\02四图'
if not os.path.exists(four):  # 判断存放图片的文件夹是否存在
    os.makedirs(four)  # 若图片文件夹不存在就创建



# 定义文件所在文件夹
image_dir = r'C:\Users\jg2yXRZ\OneDrive\桌面\儿童正脸\01原始下载'
for parent, dir_name, file_names in os.walk(image_dir):  # 遍历每一张图片
    for filename in file_names:
        print(filename)
        pic_name = os.path.join(parent, filename)
        image = Image.open(pic_name)
        _width, _height = image.size
        print(_width, _height)


        qfall=4
        # 每张图有4个坐标
        n=0  
        for p in range(int(len(pic)/4)):
            pp=pic[p*4:p*4+4]
            print(pp)

                    
            # 定义裁剪范围(left, upper, right, lower)1024
            # # box = image.crop((0,0,123,123))
            box = image.crop((pp[0],pp[1],pp[2],pp[3]))
            name = filename[:-4]+'_'+str(n) +'.png'
            
            print(name)
            # # # ,pp[3],pp[4],pp[5],pp[6],pp[7],pp[8],pp[9]))
            # # name = filename[:-4]+'_'+str(p) +'.png'2048
            
            box.save(four+r'\{}'.format(name))
            n+=1
            
#

dc071b452ecb45a69eb38cd8f1dbb4d5.pngdecbaeac66a2499bb67a25c8889168e4.png删除图片

73dd57eb9ee848548ef185173348580a.png

四、挑选单人大图

e9cd5faa97f84bfeb5c44922cae2f2ad.png五:切割半张脸的效果(左侧图和右侧图)


# 参考网址:https://blog.csdn.net/weixin_42182534/article/details/125773141?ops_request_misc=&request_id=&biz_id=102&utm_term=python%E6%88%AA%E5%8F%96%E5%9B%BE%E7%89%87%E7%9A%84%E4%B8%80%E9%83%A8%E5%88%86&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-125773141.nonecase&spm=1018.2226.3001.4187

'''

功能:把1024图片切割左右两半
作者:阿夏
时间:2024年3月2日
'''

import os
import os.path

from PIL import Image

# 图片大小是1024*1024
cood=[[0,0,512,1024],[512,0,1024,1024]]
# 左边距,上边距,右边距,下边距

path=r'C:\Users\jg2yXRZ\OneDrive\桌面\儿童正脸'

h=['']

name=['04左脸图','05右脸图']
# ys=['信息窗','主题知识']

for i in range(len(name)):

    imagePath1=path+r'\{}'.format(name[i])
    if not os.path.exists(imagePath1):  # 判断存放图片的文件夹是否存在
        os.makedirs(imagePath1)  # 若图片文件夹不存在就创建
    else:
        pass

    # 定义文件所在文件夹
    image_dir = path+r'\03单图'
    for parent, dir_name, file_names in os.walk(image_dir):  # 遍历每一张图片
        for filename in file_names:
            # print(filename)
            # 第19周 中4班 信息窗主题知识(2024.6.24——2024.6.28)1.png   
            pic_name = os.path.join(parent, filename)
            image = Image.open(pic_name)
            _width, _height = image.size
            # print(_width, _height)
   
            a=cood[i][0]
            b=cood[i][1]
            c=cood[i][2]
            d=cood[i][3]        
                    
            # 定义裁剪范围(left, upper, right, lower)1024
            # # box = image.crop((0,0,123,123))
            box = image.crop((a,b,c,d))
            box.save(imagePath1+r'\\{}'.format(filename))          
        # print('Done!')   

b865927d358246c581b599031cdd8c1a.pngf781362649a64174a03f7f6168cf2127.png

892f32833a1a462e97c754a8ebbd99be.png

六、制作左脸图4张和右脸图4张

bbd0be02b0024e41893fadd1984896a0.png

word模板 ——插入2行4列,

21be18e6a3b242c4a7ca915c406aaa48.png

代码展示

'''
目的:A4横版 一页6个半脸(左侧脸、右侧脸
时间:2024年3月2日17:27

# '''

num=int(input('生成几份?\n'))

print('----------第1-1步:提取所有的幼儿照片的路径------------')
import os

p=r"C:\Users\jg2yXRZ\OneDrive\桌面\儿童正脸"

tall=['04左脸图','05右脸图']

path=[]
for t3 in range(len(tall)):
    path.clear()
    p1=p+r'\{}'.format(tall[t3])
    print(p1)

    imgs=os.listdir(p1)
    for img in imgs:
        if img.endswith(".png"):
            path.append(p1+'\\'+img)
    # 所有图片的路径
    print(path)
    # 提取动物名字倒数第4个字之前的动物名字
    print(imgs)

    print('----------第-2步:坐标提取------------')
    bg=[]
    for x in range(0,2):
        zb=int('{}'.format(t3))
        for y in range(zb,4,2):
            # for y in range(0,4,2):        # 左侧插图
            # for y in range(1,4,2):        # 右侧插图
            bg.append('{}{}'.format('%02d'%x,'%02d'%y))
    print(bg)





    print('----------第2步:新建一个临时文件夹------------')
    # 新建一个”装N份word和PDF“的文件夹
    imagePath1=p+r'\零时Word'
    if not os.path.exists(imagePath1):  # 判断存放图片的文件夹是否存在
        os.makedirs(imagePath1)  # 若图片文件夹不存在就创建


    print('----------第3步:随机抽取4张图片 ------------')

    import docx
    from docx import Document
    import random
    import os,time
    from docx.shared import Inches,Cm,Pt
    from docx.shared import RGBColor
    from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
    # # from docx.enum.text import WD_VERTICAL_ALIGNMENT
    # from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT         #用来设置单元格垂直对齐方式
    from docx.oxml.ns import qn

    from docxtpl import DocxTemplate
    import pandas as pd
    from docx2pdf import convert
    from docx.shared import RGBColor


    for nn in range(0,num):      # 读取图片的全路径  的数量 31张
        
        doc = Document(p+r'\对称脸.docx')
        
        figures=random.sample(path,4)    # 随机抽取4个图片
        print(figures)
    #     for z in range(0): 
        table = doc.tables[0]       
        for t in range(len(bg)):   # 02
            pp=int(bg[t][0:2])    
            qq=int(bg[t][2:4])  
            print(p)               
            k=figures[t]
            # print(pp,qq,k)        

    #
            # 写入1张大图
            run=doc.tables[0].cell(pp,qq).paragraphs[0].add_run()        # # 图片位置 第一个表格的0 3 插入照片
            run.add_picture(r'{}'.format(k),width=Cm(5.00),height=Cm(9.9))
            if t3==0:
                table.cell(pp,qq).paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT #居中 
            if t3==1:
                table.cell(pp,qq).paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.LEFT #居中 
                    
        doc.save(imagePath1+r'\{}.docx'.format('%02d'%nn))  
        



    # 19份docx合并成1个pdf

    import os
    from docx2pdf import convert
    from PyPDF2 import PdfMerger

    # 获取docx文件列表
    docx_files = os.listdir(imagePath1)
    docx_files = [f for f in docx_files if f.lower().endswith('.docx')]
    docx_files = docx_files[:]  # 只处理前10个docx文件 所有文件都处理

    # 将docx文件转换为PDF
    pdf_files = []
    for docx_file in docx_files:
        docx_path = os.path.join(imagePath1, docx_file)
        pdf_file = docx_file[:-5] + '.pdf'
        pdf_path = os.path.join(imagePath1, pdf_file)
        convert(docx_path, pdf_path)
        pdf_files.append(pdf_path)

    # 合并PDF文件
    merger = PdfMerger()
    for pdf_file in pdf_files:
        merger.append(pdf_file)

    # 保存合并后的PDF文件
    output_file = os.path.join(p, '(打印)儿童脸部对称图-{}({}份).pdf'.format(tall[t3][2:],num))
    merger.write(output_file)
    merger.close()

    print('合并完毕,结果保存在{}'.format(p))


    # # print('----------第5步:删除临时文件夹------------')    
    import shutil
    shutil.rmtree(imagePath1) #递归删除文件夹,即:删除非空文件夹

8ff4e4f8e7234f3d83463ede3aa5c8b4.png

2d5523e4f9f6448894a7f31f925bd855.png

ceb44025c8bc4a53b334cb5b7d4adb6a.png

a7c904cd571c4f768ae1a408929c4bd3.png

5995b36764804772a0585af93edaac4d.png

c97143187c7242c6b0b1f0fc6f9f906b.png

幼儿书写状态下,左侧有图案,右侧绘画是比较好的学具选择

为了增加难度,我还让程序继续生成第2套右脸图的docx和PDF

ec2e8883d64648c3baaf4a35566487d9.png

07098d1489fb46c8a1f5c26d9f6f539a.png

691aae8e8e984d9ebbcc6c65ba530d48.png

1ba2f58e694249ecb6b83008f5132856.png

其他说明:

1、原来使用转PDF的代码

5c3cc94ad92a4bfb9079c3eacc882ae0.png2、现在使用转PDF的代码——代码更直观

412c1dead09e4ba2a1e4e4f66d9da689.png3、但是两个代码生成、转PDF、合并PDF用的时间是一样,30份生成了10分钟。

4、生成的图片基本都是女孩,应该再生成男孩头像,但是我的MJ用量不多了,我还想制作其他学具简笔画图片。因此就不重新生成这款“儿童正面像”的图案了。

dc7ed34c7b2842249dd7031e6bb1a0b4.png

5、考虑从这些宫格图例提取人像,但是宫格图的每个小图案位置有差异,不可能套用“等距切割”的代码,可能需要用PS提取图片,放在1024*1024大小的白色psd文件里,另存,这就比较费时了。

日后有教学需求,再提取红框部分第8-10次获取的“男女儿童”图片,代码通用

d437c8471c454f71a94d7f86809d9ee6.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿夏reasonsummer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值