当前位置: 首页 > article >正文

【教学类-36-10】20250531蝴蝶图案描边,最适合大小(一页1图1图、2图图案不同、2图图案相同对称)


背景说明:

之前做了动物头像扇子(描边20),并制作成一页一套图案对称两张

【教学类-36-09】20250526动物头像扇子的描边(通义万相)对称图40张,根据图片长宽,自动旋转图片,最大化图片-CSDN博客文章浏览阅读1k次,点赞37次,收藏6次。【教学类-36-09】20250526动物头像扇子的描边(通义万相)对称图40张,根据图片长宽,自动旋转图片,最大化图片 https://blog.csdn.net/reasonsummer/article/details/148241058?sharetype=blogdetail&sharerId=148241058&sharerefer=PC&sharesource=reasonsummer&spm=1011.2480.3001.8118

现在我需要用把“蝴蝶”做成描边、一页一图、一页两图样式

【教学类-36-07】20230707三只对称蝴蝶(midjounery-niji)(涂色、裁剪、游戏(飞舞的蝴蝶))_对称图案涂色-CSDN博客文章浏览阅读586次。【教学类-36-07】20230707三只对称蝴蝶(midjounery-niji)(涂色、裁剪、游戏(飞舞的蝴蝶))_对称图案涂色 https://blog.csdn.net/reasonsummer/article/details/131598617?spm=1011.2415.3001.5331

WORD模版

图片处理

添加点状描边,因为用了5磅的圆点,所以只做了描边20磅

'''
将已经白色P图的图案放大、透明、描边、切边deepseek,阿夏
20250531
'''
from PIL import Image, ImageDraw
import os
import math# 放大和透明室共有
print('------0、基本信息-----')
# 主路径
path = r'D:\test\20桌面素材\蝴蝶\蝴蝶2.0'
# path=r'D:\图片\20240614蛋筒彩蛋# 图片夹名称
a = '01'
b = '蝴蝶'
c = '虚线描边'# # 保存
# all = path + fr'\{a}_10{b}合并图'# 参数设置# 1、内部花纹框
# 花纹边框颜色((内部)
cchw = 0
# 调整蓝色区域边框宽度(像素)
blue_width = 0# 2、轮廓线
# 轮廓线黑线边框颜色(中间150,150,150)
ccn = 0
# 轮廓线的宽度
mb_border_width = 1  # 黑边宽度(像素)
w = int(mb_border_width / 2)  # 内5外5# 5、画布尺寸放大
target_width = 2000  # 统一宽度
target_height = target_width  # 统一高度
background_expand = 1000  # 白色背景放大尺寸# 6、添加中线虚线(折痕)# Parameters for center line# 中线参数
xxx = 0  # 颜色
total_line_width = 10  # 总宽度10磅
left_width = int(total_line_width) / 2  # 左边5磅
right_width = left_width  # 右边
# line_width = 10  # 线条粗细
dash_length = 30  # 黑线段
gap_length = 30  # 白线段# 定义文件夹路径
in_folder = os.path.join(path, f'{a}_01{b}白色')  # 原始图片(白背景)
big_folder = os.path.join(path, f'{a}_02{b}{c}放大背景')  # 放大背景输出
transparent_folder = os.path.join(path, f'{a}_03{b}{c}透明背景')  # 透明背景输出
# output_folder = os.path.join(path, f'{a}_04{b}{c}黑边轮廓')  # 最终输出
dotput_folder = os.path.join(path, f'{a}_05{b}{c}黑边点虚线轮廓')  # 最终输出
# input_folder = output_folder  # 原始图片文件夹# 创建输出文件夹
# os.makedirs(all, exist_ok=True)
# os.makedirs(output_folder,exist_ok=True)
os.makedirs(dotput_folder, exist_ok=True)
os.makedirs(big_folder, exist_ok=True)
os.makedirs(transparent_folder, exist_ok=True)rrh, ggh, bbh = cchw, cchw, cchwprint('------1、白色PNG背景放大一点-----')
# 遍历输入文件夹中的所有PNG文件
for filename in os.listdir(in_folder):if filename.lower().endswith('.png'):# 打开原始图片input_path = os.path.join(in_folder, filename)with Image.open(input_path) as img:original_width, original_height = img.size# 创建新画布(长宽各+200,白色背景)new_width = original_width + background_expandnew_height = original_height + background_expandnew_image = Image.new('RGB', (new_width, new_height), (255, 255, 255))# 计算粘贴位置(居中)paste_x = (new_width - original_width) // 2paste_y = (new_height - original_height) // 2# 将原始图片粘贴到新画布上new_image.paste(img, (paste_x, paste_y), img if img.mode == 'RGBA' else None)# 保存结果big_path = os.path.join(big_folder, filename)new_image.save(big_path)print('------2、白色PNG背景变成透明-----')
def process_image_to_transparent(file_path):img = Image.open(file_path)img = img.convert("RGBA")datas = img.getdata()new_data = []for item in datas:if item[0] == 255 and item[1] == 255 and item[2] == 255:new_data.append((255, 255, 255, 0))else:new_data.append(item)img.putdata(new_data)return imgprint("正在转换白背景为透明背景...")
for file_name in os.listdir(big_folder):if file_name.lower().endswith((".png", ".jpg", ".jpeg")):input_file_path = os.path.join(big_folder, file_name)output_file_path = os.path.join(transparent_folder, file_name)processed_image = process_image_to_transparent(input_file_path)processed_image.save(output_file_path)print(f"已处理: {file_name}")# 描边为20、50、80
for x in [20]:cropped_folder = os.path.join(path, f'{a}_06{b}{c}切边{x}')  # 裁剪后的透明图片os.makedirs(cropped_folder, exist_ok=True)# 3、点状虚线裁剪边# 点状虚线边框颜色(外边)ccw = 150# 白色描边宽度(像素)轮廓线外层white_border_width = x# 黑点直径(像素)dot_size = 5# # 黑点间距(像素)增加间距确保均匀分布  dot_spacing = dot_size * 2# 4、裁剪时不保留额外透明边距transparent_edge = 0  # 裁剪时不保留额外透明边距# 灰线深浅测试# for cr3 in range(cchw,cchw+10,10):# 黑色边框颜色# 灰色# if x==1:#   中线(内)    rrw = ggw = bbw = ccwrrn = ggn = bbn = ccnrrh = ggh = bbh = cchwrrx = ggx = bbx = xxxprint('------3、添加点状虚线轮廓-----')def get_edge_pixels(image):"""获取图像中不透明像素与透明像素交界的边缘像素坐标"""edge_pixels = []pixels = image.load()width, height = image.sizefor y in range(height):for x in range(width):if pixels[x, y][3] > 0:  # 不透明像素# 检查4邻域for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:nx, ny = x + dx, y + dyif 0 <= nx < width and 0 <= ny < height:if pixels[nx, ny][3] == 0:  # 邻域透明edge_pixels.append((x, y))breakreturn edge_pixelsdef expand_edge_pixels(edge_pixels, distance, width, height):"""扩展边缘像素坐标到指定距离"""expanded_pixels = set()for x, y in edge_pixels:for dy in range(-distance, distance + 1):for dx in range(-distance, distance + 1):nx, ny = x + dx, y + dyif 0 <= nx < width and 0 <= ny < height:expanded_pixels.add((nx, ny))return expanded_pixelsdef get_contour_pixels(border_pixels, width, height):"""获取白边区域的外轮廓像素(使用边缘追踪算法)"""# 找到起始点(最左上角的边界像素)start_point = Nonefor y in range(height):for x in range(width):if (x, y) in border_pixels:start_point = (x, y)breakif start_point:breakif not start_point:return []# 使用Moore-Neighbor追踪算法获取轮廓contour = []current = start_pointprevious = (current[0] - 1, current[1])  # 假设从左侧开始directions = [(0, -1), (1, -1), (1, 0), (1, 1),(0, 1), (-1, 1), (-1, 0), (-1, -1)]while True:contour.append(current)# 找到下一个
http://www.lryc.cn/news/2400918.html

相关文章:

  • 高效DBA的日常运维主题沙龙
  • AAAI 2025论文分享│STD-PLM:基于预训练语言模型的时空数据预测与补全方法
  • Ethernet/IP转DeviceNet网关:驱动大型矿山自动化升级的核心纽带
  • Android 11以上App主动连接WIFI的完整方案
  • [蓝桥杯]模型染色
  • 力扣上C语言编程题
  • 卡西欧模拟器:Windows端功能强大的计算器
  • 鸿蒙OSUniApp结合机器学习打造智能图像分类应用:HarmonyOS实践指南#三方框架 #Uniapp
  • 机器学习基础(三) 逻辑回归
  • 系统调试——ADB 工具
  • Qwen-3 微调实战:用 Python 和 Unsloth 打造专属 AI 模型
  • 微软Build 2025:Copilot Studio升级,解锁多智能体协作未来
  • 设计模式——系统数据建模设计
  • 解决docker运行zentao 报错:ln: failed to create symbolic link ‘/opt/zbox/tmp/mysq
  • Spring Boot MVC自动配置与Web应用开发详解
  • OA工程自动化办公系统 – 免费Java源码
  • Apache IoTDB V2.0.3 发布|新增元数据导入导出脚本适配表模型功能
  • 某校体育场馆结构自动化监测
  • MySQL 9.0 相较于 MySQL 8.0 引入了多项重要改进和新特性
  • Android 3D球形水平圆形旋转,旋转动态更换图片
  • 数据结构与算法学习笔记(Acwing 提高课)----动态规划·树形DP
  • FTP 和 SFTP 介绍及 C/C++ 实现分析
  • leetcode hot100刷题日记——36.最长连续序列
  • CentOS7关闭防火墙、Linux开启关闭防火墙
  • PyTorch——搭建小实战和Sequential的使用(7)
  • 基于大模型的腔隙性脑梗塞风险预测及治疗方案研究
  • Python 开发效率秘籍:PyCharm、VS Code 与 Anaconda 配置与实战全解
  • [C]C语言日志系统宏技巧解析
  • 自动驾驶系统研发系列—激光雷达感知延迟:自动驾驶安全的隐形隐患?
  • 内网应用如何实现外网访问?无公网IP本地端口网址服务提供互联网连接