对称!

纯搞笑的,但是很好笑。

import tkinter as tk
from tkinter import ttk, filedialog, messagebox
from PIL import Image, ImageTk
class ImageSymmetryApp:
def __init__(self, root):
self.root = root
self.root.title("图片对称处理工具")
# 初始化变量
self.original_image = None
self.processed_image = None
self.display_width = 800 # 预览区最大宽度
self.display_height = 600 # 预览区最大高度
# 创建界面组件
self.create_widgets()
def create_widgets(self):
# 控制面板
control_frame = ttk.Frame(self.root)
control_frame.pack(padx=10, pady=10, fill=tk.X)
# 文件选择按钮
ttk.Button(
control_frame,
text="选择图片",
command=self.load_image
).grid(row=0, column=0, padx=5)
# 方向选择下拉框
self.side_var = tk.StringVar(value="left")
ttk.Combobox(
control_frame,
textvariable=self.side_var,
values=["left", "right"],
state="readonly",
width=8
).grid(row=0, column=1, padx=5)
# 处理按钮
ttk.Button(
control_frame,
text="生成对称图",
command=self.process_image
).grid(row=0, column=2, padx=5)
# 保存按钮
ttk.Button(
control_frame,
text="保存结果",
command=self.save_image
).grid(row=0, column=3, padx=5)
# 图片预览区域
self.preview_label = ttk.Label(self.root)
self.preview_label.pack(padx=10, pady=10)
def load_image(self):
file_path = filedialog.askopenfilename(
filetypes=[("图片文件", "*.jpg;*.jpeg;*.png;*.bmp")]
)
if file_path:
try:
self.original_image = Image.open(file_path)
self.show_preview(self.original_image)
except Exception as e:
messagebox.showerror("错误", f"无法打开图片:\n{str(e)}")
def process_image(self):
if not self.original_image:
messagebox.showwarning("提示", "请先选择图片")
return
selected_side = self.side_var.get()
width, height = self.original_image.size
mid = width // 2
# 根据选择的侧边进行处理
if selected_side == "left":
left_part = self.original_image.crop((0, 0, mid, height))
mirrored = left_part.transpose(Image.FLIP_LEFT_RIGHT)
self.processed_image = Image.new("RGB", (width, height))
self.processed_image.paste(left_part, (0, 0))
self.processed_image.paste(mirrored, (mid, 0))
else:
right_part = self.original_image.crop((mid, 0, width, height))
mirrored = right_part.transpose(Image.FLIP_LEFT_RIGHT)
self.processed_image = Image.new("RGB", (width, height))
self.processed_image.paste(mirrored, (0, 0))
self.processed_image.paste(right_part, (mid, 0))
self.show_preview(self.processed_image)
def show_preview(self, image):
# 缩放图片适应预览区域
img = image.copy()
img.thumbnail((self.display_width, self.display_height))
photo = ImageTk.PhotoImage(img)
# 更新预览
self.preview_label.configure(image=photo)
self.preview_label.image = photo # 保持引用
def save_image(self):
if not self.processed_image:
messagebox.showwarning("提示", "没有可保存的图片")
return
save_path = filedialog.asksaveasfilename(
defaultextension=".png",
filetypes=[
("PNG 文件", "*.png"),
("JPEG 文件", "*.jpg"),
("所有文件", "*.*")
]
)
if save_path:
try:
self.processed_image.save(save_path)
messagebox.showinfo("成功", "图片保存成功!")
except Exception as e:
messagebox.showerror("错误", f"保存失败:\n{str(e)}")
if __name__ == "__main__":
root = tk.Tk()
app = ImageSymmetryApp(root)
root.mainloop()
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇
欢迎阅读『对称!』
Nightglow - 蔡健雅
00:00
  1. Nightglow蔡健雅
  2. やわらかな光やまだ豊

作曲 : 蔡近翰Zoe

作词 : 尹纯青Eyn

编曲:宫奇Gon/Luna Safari

The way I go through with red roses burn my eyes.
道途之上,赤玫瑰灼烧我的双目

Cold rain starts pouring hard, I'm being called upon.
冷雨如注,我于此只为一声召唤

Never let you go, it's why I did them all.
绝不放弃你,是我做这一切的原因

For a chance at least, to live in your way.
至少这一次,以自己的方式活吧

Love of you is my most cherished thing.
予你的爱是我最珍惜的事物

So stay alive, bravely.
所以请勇敢,活下去


I wish I could wake from the dream each time I dream.
我希望从夙夜梦寐中苏醒

There's a long night coming soon,I'd shine as the last shine.
很快长夜将至,我愿化作最后的光芒

Never let you go,it's why I did them all.
绝不放弃你,是我做这一切的原因

For a chance at least, to live in your way.
至少这一次,以自己的方式活吧

Love of you is my most cherished thing.
予你的爱是我最珍惜的事物

So stay alive, bravely.
所以请勇敢,活下去


Never let you go,it's why I did them all.
绝不放弃你,是我做这一切的原因

For a chance at least, to live in your way.
至少这一次,以自己的方式活吧

Love of you is my most cherished thing.
予你的爱是我最珍惜的事物

So stay alive, bravely.
所以请勇敢,活下去


混音:宫奇Gon

制作人:蔡近翰Zoe Music by HOYO-MiX