Lychee 相册 PHP Artisan 命令笔记

一、进入容器环境

Podman 进入容器

podman exec -it lychee /bin/sh
# 或使用 bash
podman exec -it lychee /bin/bash

切换到正确的工作目录

Lychee 程序所在目录通常为 /app/www

cd /app/www

二、常用 Artisan 命令

1. 查看所有 lychee 相关命令

php artisan list | grep lychee

2. 生成缩略图 / 图片变体

不同版本的 Lychee 命令名称不同:

版本/情况命令
较新版本php artisan lychee:generate_variants
旧版本php artisan lychee:generate_thumbs <type>

3. generate_thumbs 命令详解

php artisan lychee:generate_thumbs <type> [<amount> [<timeout>]]

参数说明:

  • type - 缩略图类型(必需)
  • amount - 处理照片数量,默认 100
  • timeout - 超时时间(秒),默认 600

常见 type 类型:

类型用途
thumb小缩略图(相册列表视图)
small小尺寸照片
medium中等尺寸照片(点进相册后默认显示)

4. 执行示例

# 生成中等尺寸缩略图,处理 100 张
php artisan lychee:generate_thumbs medium

# 生成中等尺寸,处理 500 张
php artisan lychee:generate_thumbs medium 500

# 生成所有类型(建议按顺序执行)
php artisan lychee:generate_thumbs thumb 99999
php artisan lychee:generate_thumbs small 99999
php artisan lychee:generate_thumbs medium 99999

5. 其他有用命令

# 查看框架版本
php artisan --version

# 查看帮助信息
php artisan lychee:generate_thumbs --help

# 全量维护(自动处理所有照片变体)
php artisan lychee:maintenance

三、执行结果解读

成功示例

Will attempt to generate up to 100 medium images with a timeout of 600 seconds...
 0/8 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%   medium (480x640) for photo_xxx.jpg created.
 8/8 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

"No picture requires" 含义

表示该类型的缩略图已经全部存在,无需重新生成。


四、何时需要手动执行?

场景是否需要执行
日常通过 Web 界面上传新照片❌ 自动生成,无需手动
刚迁移或导入大量历史照片✅ 运行一次补齐缺失
修改了缩略图尺寸设置✅ 按新尺寸重新生成
缩略图显示异常/损坏✅ 针对性补全
从旧版本升级后✅ 建议运行一次

五、Podman 常见问题

错误:Could not open input file: artisan

原因:当前工作目录不正确,未找到 artisan 文件。

解决方法

  1. 先查找 artisan 文件位置:

    find / -name "artisan" 2>/dev/null
  2. 切换到正确目录(常见路径:/app/www/lychee/var/www/html
  3. 或使用 -w 参数直接指定工作目录:

    podman exec -it -w /app/www lychee php artisan lychee:generate_thumbs medium

错误:Command "lychee:generate_variants" is not defined

原因:当前版本使用了不同的命令名称。

解决方法

  1. 先查看可用命令列表:

    php artisan list | grep lychee
  2. 使用系统提示的替代命令(如 lychee:generate_thumbs

六、完整操作流程(推荐)

首次部署/迁移后执行

命令用途
lychee:generate_thumbs生成缩略图(你已使用过)
lychee:recompute-album-sizes重新计算相册大小
lychee:recompute-album-stats重新计算相册统计信息
lychee:fix-tree修复相册树结构
lychee:diagnostics系统诊断
# 1. 进入容器
podman exec -it lychee /bin/sh

# 2. 切换到程序目录
cd /app/www

# 3. 查看可用命令(确认版本)
php artisan list | grep lychee

# 4. 生成所有缩略图
php artisan lychee:generate_thumbs thumb 99999
php artisan lychee:generate_thumbs small 99999
php artisan lychee:generate_thumbs medium 99999
php artisan lychee:recompute-album-sizes
php artisan lychee:recompute-album-stats
# 5. 退出容器
exit

不过对于日常使用,只需要 generate_thumbs 就足够了,其他命令不是必需的。

修改缩略图尺寸后执行

# 只需要重新生成 medium 类型
podman exec -it -w /app/www lychee php artisan lychee:generate_thumbs medium 99999

标签: none

添加新评论