phaser4-game-image-optimization

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Phaser 4 图片资源优化

Phaser 4 Image Resource Optimization

全局控制接入

Global Control Access

控制面边界:可提议、可审查、可在已建立且任务授权有效的 Work Item 范围内修改,且必须回到
$phaser4-game-workflow-control
审计和状态迁移;仅实际 A4-A6 操作请求批准。
显式调用只触发提案,不等于授权写入。所有盘点、候选生成、替换和验证都必须进入
phaser4-game-workflow-control
;本 Skill 不拥有全局状态或审批,不得旁路 diff 审计与证据门。
在保持视觉质量、运行时行为和渠道兼容性的前提下压缩运行时图片体积,并给出可复现的优化报告。
Control plane boundaries: Proposals, reviews, and modifications are allowed within the scope of established and task-authorized Work Items, and must return to
$phaser4-game-workflow-control
for audit and state migration; only actual A4-A6 operation requests require approval.
Explicit invocation only triggers a proposal and does not equal authorization for writing. All inventory, candidate generation, replacement, and verification must be incorporated into
phaser4-game-workflow-control
; this Skill does not own global state or approval rights, and must not bypass diff audits and evidence gates.
Compress the size of runtime images while maintaining visual quality, runtime behavior, and channel compatibility, and provide a reproducible optimization report.

执行边界

Execution Boundaries

  • 只有用户显式调用
    $phaser4-game-image-optimization
    时才提出任务;A0-A3 写入使用独立 Work Item 的任务授权,实际 A4-A6 操作才请求精确批准。不得因包体偏大、进入发布阶段、执行构建或运行测试而自动调用。
  • 将本任务视为显式触发的资源领域任务,并按实际动作纳入 A0-A3、本地阶段与统一门;不得自动加入构建脚本、Git 钩子或 CI,也不得由发布状态隐式触发。
  • 默认只处理项目内被运行时代码、资源清单或加载配置引用的 PNG、JPEG 和 WebP。设计源文件、参考图、审核证据、截图、测试夹具、构建产物、缓存以及未被运行时引用的素材不在范围内。
  • GIF、APNG、纹理图集、法线图、像素画、九宫格和带特殊色彩空间的图片属于高风险资源;保留其帧、像素网格、通道、边界和元数据语义,只在相应验证可执行时处理。
  • Only propose the task when the user explicitly calls
    $phaser4-game-image-optimization
    ; A0-A3 writes use task authorization from independent Work Items, and only actual A4-A6 operations require precise approval. It must not be automatically invoked due to large package size, entering the release phase, executing builds, or running tests.
  • Treat this task as an explicitly triggered resource domain task, and incorporate it into A0-A3, local phases, and unified gates according to actual actions; it must not be automatically added to build scripts, Git hooks, or CI, nor implicitly triggered by release status.
  • By default, only process PNG, JPEG, and WebP files referenced by runtime code, resource manifests, or loading configurations within the project. Design source files, reference images, audit evidence, screenshots, test fixtures, build artifacts, caches, and unused runtime materials are excluded.
  • GIF, APNG, texture atlases, normal maps, pixel art, nine-slice images, and images with special color spaces are high-risk resources; retain their frames, pixel grids, channels, boundaries, and metadata semantics, and only process them when corresponding verification is executable.

优化流程

Optimization Process

  1. 确定用户指定的目录、目标渠道、允许格式、画质底线和体积目标。未指定目录时,从资源加载代码、资源清单和构建入口反查实际运行时图片,不对项目外路径或整个磁盘做宽泛扫描。
  2. 建立压缩前基线,逐文件记录路径、引用位置、格式、字节数、宽高、透明通道、动画或图集属性,并汇总总大小。使用内容哈希识别重复文件,但未经引用分析不得合并或删除。
  3. 在独立候选目录生成结果,禁止直接覆盖原文件。记录优化工具、固定版本、完整参数和退出状态;优先复用项目已有工具,不为一次性任务增加运行时依赖。
  4. 默认保持原格式、尺寸、方向和文件名:
    • PNG 优先执行无损元数据清理与无损压缩;只有画质底线允许且透明边缘、渐变和像素差异验证齐全时才使用有损调色板量化。
    • JPEG 仅处理不依赖透明度的图片,使用受控质量的渐进式压缩并移除非必要元数据,不改变 EXIF 方向呈现。
    • WebP 先判断是否已经接近最优;重复有损编码没有明确收益时保留原文件。
    • 只有用户允许格式迁移,且目标渠道、Phaser 加载器和降级策略均已验证时,才转换为 WebP 或 AVIF;同步修改引用、资源清单和加载配置,不保留无引用的双份运行时资源。
    • 精灵表、纹理图集、九宫格和像素画不得缩放、裁切、补边、重排或改变帧坐标,只允许压缩其图像容器。
  5. 对每个候选执行结构与画质验证:解码成功;宽高、方向、透明度、帧数和图集坐标保持一致;无损候选比较解码后像素;有损候选检查透明边缘、渐变、文字、细线、像素网格和代表性放大差异。证据不足时保留原文件并标记“未验证”。
  6. 在 Phaser 中实际加载受影响资源,并验证至少一个引用场景;涉及图集、九宫格、像素画或动画时验证对应运行状态。随后运行受影响测试和生产构建,确认无加载错误、路径错误、采样异常或候选文件误入构建。
  7. 只有候选体积更小且全部适用验证通过时才替换原文件;任一验证失败、体积不降或收益不足以抵偿画质与兼容风险时保留原文件。替换后再次核对引用与版本控制差异,确保修改范围仅包含获准资源及必要引用。
  1. Determine the user-specified directory, target channel, allowed formats, image quality baseline, and volume target. When no directory is specified, reverse-engineer actual runtime images from resource loading code, resource manifests, and build entries, and do not perform broad scans of paths outside the project or the entire disk.
  2. Establish a pre-compression baseline, recording path, reference location, format, byte count, width and height, transparency channel, animation or atlas attributes file by file, and summarize the total size. Use content hashing to identify duplicate files, but do not merge or delete them without reference analysis.
  3. Generate results in an independent candidate directory; direct overwriting of original files is prohibited. Record the optimization tool, fixed version, complete parameters, and exit status; prioritize reusing existing project tools and do not add runtime dependencies for one-time tasks.
  4. Keep the original format, size, orientation, and file name by default:
    • For PNG, prioritize lossless metadata cleaning and lossless compression; only use lossy palette quantization when the image quality baseline allows and verification of transparent edges, gradients, and pixel differences is complete.
    • For JPEG, only process images that do not rely on transparency, use controlled-quality progressive compression and remove unnecessary metadata, without changing EXIF orientation presentation.
    • For WebP, first determine if it is already near optimal; retain the original file if repeated lossy encoding provides no clear benefit.
    • Only convert to WebP or AVIF when the user allows format migration, and the target channel, Phaser loader, and downgrade strategy have all been verified; synchronously modify references, resource manifests, and loading configurations, and do not retain duplicate runtime resources without references.
    • Sprite sheets, texture atlases, nine-slice images, and pixel art must not be scaled, cropped, padded, rearranged, or have their frame coordinates changed; only compression of their image containers is allowed.
  5. Perform structure and image quality verification on each candidate: successful decoding; consistent width and height, orientation, transparency, frame count, and atlas coordinates; compare decoded pixels for lossless candidates; check transparent edges, gradients, text, thin lines, pixel grids, and representative zoom differences for lossy candidates. Retain the original file and mark it as "unverified" if evidence is insufficient.
  6. Actually load the affected resources in Phaser and verify at least one reference scenario; verify the corresponding runtime status when atlases, nine-slice images, pixel art, or animations are involved. Then run affected tests and production builds to confirm no loading errors, path errors, sampling anomalies, or candidate files entering the build by mistake.
  7. Replace the original file only if the candidate has a smaller volume and all applicable verifications pass; retain the original file if any verification fails, volume does not decrease, or the benefit does not offset the risks of image quality and compatibility. After replacement, recheck references and version control differences to ensure the modification scope only includes approved resources and necessary references.

结果报告

Result Report

在用户指定位置或项目既有证据目录写入报告;两者都不存在时直接在任务结果中提交,不擅自创建长期流程文档。报告至少包含:
  • 优化范围、排除项、目标渠道、工具版本与参数;
  • 每个文件的原始大小、优化后大小、节省字节数与比例,以及保留或拒绝原因;
  • 总体积前后对比,分别列出源资源与生产构建中的实际变化;
  • 结构、画质、Phaser 运行、测试和生产构建证据;
  • 格式迁移产生的引用修改、未验证项、剩余风险和回退方式。
不得用“命令成功”代替画质与运行验证,也不得在缺少压缩前基线时声称已节省体积。
Write the report to the user-specified location or the project's existing evidence directory; if neither exists, submit it directly in the task result and do not create long-term process documents without permission. The report must include at least:
  • Optimization scope, exclusions, target channels, tool versions and parameters;
  • Original size, optimized size, bytes saved and ratio for each file, as well as reasons for retention or rejection;
  • Overall volume comparison before and after, listing actual changes in source resources and production builds separately;
  • Evidence of structure, image quality, Phaser runtime, testing, and production builds;
  • Reference modifications caused by format migration, unverified items, remaining risks, and rollback methods.
Do not replace image quality and runtime verification with "command successful", and do not claim volume savings without a pre-compression baseline.