【教程】如何下载ns的官方小黄鸡图片,并等比例放大做成表情包

肥狗在线 2026-07-17 11:41 1

最近想把 NodeSeek 的 xhj 系列表情包(001~032)全部下下来做微信表情,根据贴子里面大佬的指引和提醒,然后写了个脚本,结果直接发现下载 .png 会失败 20 个。后面发现原因是这个系列部分是 .png,部分是 .gif。现在用grok优化了脚本,会自动判断格式:优先尝试 .png,如果 404,就自动切换成 .gif 下载,并用正确后缀保存


使用方法:把下面脚本保存为 download_xhj.py,运行命令,然后图片会自动下载到当前目录的 xhj_stickers 文件夹


Bash

python download_xhj.py

脚本-Grok

import os
import urllib.request
from urllib.error import HTTPError, URLError
import time

# ==================== 配置 ====================
base_url = "https://www.nodeseek.com/static/image/sticker/xhj/"
save_folder = "xhj_stickers"
start_num = 1
end_num = 32
# =============================================

os.makedirs(save_folder, exist_ok=True)

print(
f"开始智能下载 {start_num:03d} ~ {end_num:03d}"
"(png 优先,失败自动尝试 gif)\n"
)

success_png = 0
success_gif = 0
fail = 0

for i in range(start_num, end_num + 1):
num = f"{i:03d}"

if (
os.path.exists(os.path.join(save_folder, f"{num}.png"))
or os.path.exists(os.path.join(save_folder, f"{num}.gif"))
):
print(f"[{num}] 已存在,跳过")
continue

downloaded = False

for ext in ["png", "gif"]:
filename = f"{num}.{ext}"
url = base_url + filename
filepath = os.path.join(save_folder, filename)

try:
print(f"[{num}] 尝试下载 {ext} ...")

req = urllib.request.Request(
url,
headers={
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
)
},
)

with urllib.request.urlopen(req, timeout=20) as response:
if response.status == 200:
with open(filepath, "wb") as f:
f.write(response.read())

print(f"[{num}] ✓ 下载成功({ext})")

if ext == "png":
success_png += 1
else:
success_gif += 1

downloaded = True
time.sleep(0.3)
break

except HTTPError as e:
if e.code == 404:
print(
f"[{num}] {ext} 不存在(404),"
"尝试下一个格式..."
)
else:
print(f"[{num}] {ext} HTTP错误 {e.code}")

except Exception as e:
print(f"[{num}] {ext} 错误: {str(e)[:60]}")

if not downloaded:
print(f"[{num}] ✗ png 和 gif 都失败\n")
fail += 1

print("\n" + "=" * 40)
print("下载完成!统计如下:")
print(f" PNG 成功: {success_png} 个")
print(f" GIF 成功: {success_gif} 个")
print(f" 失败: {fail} 个")
print(f" 总成功: {success_png + success_gif} 个")
print(f"文件保存在: {os.path.abspath(save_folder)}")
print("=" * 40)


更简单的办法是:直接打开vscode,创建一个新的脚本文件,然后复制进去保存(在某一路径下,要自己定位),然后运行脚本,这个 xhj_stickers 文件夹就会在你电脑(某一路径下)生成


二次编辑(放大图片)


因为使用下来,发现原图直接导入微信的小黄鸡太小了,随打算放大,因为没有现成的放大工具,所以让gpt写了一个脚本,也是python很简单,具体实现了:



  • 批量读取文件夹中的 PNG 和 GIF

  • 按指定倍数放大图片

  • 保留 PNG 透明背景

  • 支持动态 GIF 逐帧放大

  • 保留 GIF 播放速度和循环设置

  • 使用 LANCZOS 高质量缩放

  • 放大后进行轻微锐化

  • 自动跳过已经处理过的文件


注意要先安装python的一个包,建议直接用vscode操作更顺畅,如果安装时出现代理连接失败,可以临时取消代理(具体自己ai吧,很简单)。另外,修改顶部这三个参数即可,缩放一般就设置2或者3就行,我用下来2看起来挺顺眼的


安装

python -m pip install Pillow


完整脚本

from pathlib import Path
from PIL import Image, ImageSequence, ImageFilter

INPUT_FOLDER = r"D:\images"
OUTPUT_FOLDER = r"D:\images_upscaled"

SCALE_FACTOR = 2
OVERWRITE = False

SUPPORTED_EXTENSIONS = {".png", ".gif"}

def upscale_rgba_image(image, scale_factor, sharpen=True):
new_size = (image.width * scale_factor, image.height * scale_factor)
enlarged = image.resize(new_size, Image.Resampling.LANCZOS)

if sharpen:
enlarged = enlarged.filter(
ImageFilter.UnsharpMask(
radius=1.2,
percent=130,
threshold=2
)
)

return enlarged

def process_png(input_path, output_path, scale_factor):
with Image.open(input_path) as image:
original_size = image.size
image = image.convert("RGBA")

enlarged = upscale_rgba_image(
image,
scale_factor,
sharpen=True
)

enlarged.save(
output_path,
compress_level=6
)

print(
f"成功:{input_path.name} "
f"{original_size[0]}×{original_size[1]} -> "
f"{enlarged.width}×{enlarged.height}"
)

def process_gif(input_path, output_path, scale_factor):
with Image.open(input_path) as image:
original_size = image.size
loop = image.info.get("loop", 0)

frames = []
durations = []

previous = Image.new(
"RGBA",
image.size,
(0, 0, 0, 0)
)

for frame in ImageSequence.Iterator(image):
frame_rgba = frame.convert("RGBA")

composed = previous.copy()
composed.alpha_composite(frame_rgba)

enlarged = upscale_rgba_image(
composed,
scale_factor,
sharpen=True
)

frames.append(enlarged)

durations.append(
frame.info.get(
"duration",
image.info.get("duration", 100)
)
)

previous = composed

if not frames:
raise ValueError("GIF 中没有可处理的帧")

frames[0].save(
output_path,
save_all=True,
append_images=frames[1:],
duration=durations,
loop=loop,
optimize=False,
disposal=2
)

print(
f"成功:{input_path.name} "
f"{original_size[0]}×{original_size[1]} -> "
f"{original_size[0] * scale_factor}×"
f"{original_size[1] * scale_factor}"
)

def process_image(input_path, output_path, scale_factor):
suffix = input_path.suffix.lower()

if suffix == ".png":
process_png(
input_path,
output_path,
scale_factor
)

elif suffix == ".gif":
process_gif(
input_path,
output_path,
scale_factor
)

else:
raise ValueError(
f"不支持的格式:{suffix}"
)

def main():
input_folder = Path(INPUT_FOLDER)
output_folder = Path(OUTPUT_FOLDER)

if not input_folder.exists():
print(
f"错误:输入文件夹不存在:"
f"{input_folder}"
)
return

output_folder.mkdir(
parents=True,
exist_ok=True
)

image_files = [
path
for path in input_folder.iterdir()
if path.is_file()
and path.suffix.lower() in SUPPORTED_EXTENSIONS
]

if not image_files:
print(
"输入文件夹中没有找到 PNG 或 GIF 图片。"
)
return

success_count = 0
skipped_count = 0
failed_count = 0

print(f"共找到 {len(image_files)} 张图片")
print(f"放大倍数:{SCALE_FACTOR} 倍\n")

for input_path in image_files:
output_path = output_folder / input_path.name

if output_path.exists() and not OVERWRITE:
print(
f"跳过:{output_path.name} 已存在"
)

skipped_count += 1
continue

try:
process_image(
input_path,
output_path,
SCALE_FACTOR
)

success_count += 1

except Exception as error:
print(
f"失败:{input_path.name},"
f"原因:{error}"
)

failed_count += 1

print("\n处理完成")
print(f"成功:{success_count}")
print(f"跳过:{skipped_count}")
print(f"失败:{failed_count}")
print(f"输出文件夹:{output_folder}")

if __name__ == "__main__":
main()

参数

INPUT_FOLDER = r"D:\images"

OUTPUT_FOLDER = r"D:\images_upscaled"

SCALE_FACTOR = 2



下载好图片直接,可以发送到微信的文件传输助手,然后gif的可以直接保存,但是png的要先保存到手机的系统相库里,再在微信的添加表情吧那个加号批量添加上(最多一次9个,添加多几次就行)

最新回复 (11)
  • Zyhethan 07-17 11:50
    1

    cy

  • joingonna 07-17 11:52
    2

    有实力 ^-^

  • 维生素C 07-17 11:58
    3

    你是真的喜欢鸡,哈哈,微信聊天框表情搜索“小黄鸡”有惊喜

  • 肥狗在线 楼主 07-17 11:59
    4

    @维生素C #3 那些鸡,都不如我ns的纯血好看

  • shen1e 07-17 11:59
    5

    能不能直接分享下载好的

  • 肥狗在线 楼主 07-17 12:00
    6

    @shen1e #5 可以,我弄个官方图床,等待

    -二编

    似乎存在一些图片上传不了的问题,懒得弄了,佬要是想要可以直接复制到vscode里面就能运行

  • 祈雪于凛冬 07-17 12:00
    7

    为啥不用图片助手插件?

  • 肥狗在线 楼主 07-17 12:07
    8

    @祈雪于凛冬 #7

    有一些图片上传失败,不知道为什么

  • 鲁班 07-17 12:15
    9

    我也喜欢论坛的小黄鸡系列 ^-^

  • 肥狗在线 楼主 07-17 12:18
    10

    @鲁班 #9 有一种原汁原味的感觉

  • M1k4kk0 07-17 13:31
    11

    可以 回去搞下

    ^-^

* 帖子来源NodeSeek
返回