EZ签到(F5隐写+拼图)
得到nizhenbuhuiyiweizheshiqiandaoba
解压flag.zip
因为拼图要修改像素大小一致,所以改成40*40
import os
from PIL import Image, ImageOps
from collections import defaultdict
from tqdm import tqdm
IMG_DIR = r"C:\Temp\flag"
RESIZE_MODE = "fill" # 调整模式:fill=等比填充, crop=居中裁剪, stretch=强制拉伸
BG_COLOR = (255, 255, 255) # 填充模式下的背景色(RGB格式)
def get_image_dimensions(img_path):
"""安全获取图片尺寸"""
try:
with Image.open(img_path) as img:
return img.size
except Exception as e:
print(f"无法读取 {img_path}: {str(e)}")
return None
def analyze_dimensions():
"""统计分析图片尺寸分布"""
dimension_counts = defaultdict(int)
valid_images = []
for filename in tqdm(os.listdir(IMG_DIR), desc="分析图片"):
if filename.lower().split(".")[-1] not in ("jpg", "jpeg", "png", "webp"):
continue
path = os.path.join(IMG_DIR, filename)
dim = get_image_dimensions(path)
if dim:
dimension_counts[dim] += 1
valid_images.append((path, dim))
if not dimension_counts:
raise ValueError("未找到有效图片文件")
# 获取最高频尺寸
target_dim = max(dimension_counts.items(), key=lambda x: x[1])[0]
print(f"最高频尺寸: {target_dim} (出现次数: {dimension_counts[target_dim]})")
return target_dim, valid_images
def resize_image(img_path, target_dim):
"""按指定模式调整图片尺寸"""
try:
img = Image.open(img_path)
if img.size == target_dim:
return
if RESIZE_MODE == "stretch":
img = img.resize(target_dim, Image.LANCZOS)
elif RESIZE_MODE == "crop":
img = ImageOps.fit(
img, target_dim, method=Image.LANCZOS, centering=(0.5, 0.5)
)
else: # 默认填充模式
ratio = max(target_dim[0] / img.width, target_dim[1] / img.height)
new_size = (int(img.width * ratio), int(img.height * ratio))
img = img.resize(new_size, Image.LANCZOS)
# 创建画布并居中粘贴
canvas = Image.new("RGB", target_dim, BG_COLOR)
offset = (
(target_dim[0] - new_size[0]) // 2,
(target_dim[1] - new_size[1]) // 2,
)
canvas.paste(img, offset)
img = canvas
# 保留原始格式和质量
format = img.format or "JPEG"
save_kwargs = {"format": format}
if format == "JPEG":
save_kwargs["quality"] = 95
img.save(img_path, **save_kwargs)
except Exception as e:
print(f"处理失败: {img_path} - {str(e)}")
if __name__ == "__main__":
target_dim, images = analyze_dimensions()
# 筛选需要调整的图片
to_resize = [img[0] for img in images if img[1] != target_dim]
print(f"需要调整的图片数量: {len(to_resize)}")
# 批量处理
for path in tqdm(to_resize, desc="调整尺寸"):
resize_image(path, target_dim)
print("处理完成!")
使用magick montage *.jpg -tile 10x10 -geometry +0+0 flag.jpg
拼成一张图
使用gaps run flag.jpg flagg.jpg --generations=20 --population=20
还原
得到结果
R1kzRE1RWldHRTNET04yQ0dRMlRNTUpYSUUzVFNOS0dHVVpUTU9KV0c0M0VLTktHR1E0VE1SSlhJUT09PT09PQ==