Lychee相册PHPArtisan命令笔记
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 lychee2. 生成缩略图 / 图片变体
不同版本的 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- 处理照片数量,默认 100timeout- 超时时间(秒),默认 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 999995. 其他有用命令
# 查看框架版本
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 文件。
解决方法:
先查找 artisan 文件位置:
find / -name "artisan" 2>/dev/null- 切换到正确目录(常见路径:
/app/www、/lychee、/var/www/html) 或使用
-w参数直接指定工作目录:podman exec -it -w /app/www lychee php artisan lychee:generate_thumbs medium
错误:Command "lychee:generate_variants" is not defined
原因:当前版本使用了不同的命令名称。
解决方法:
先查看可用命令列表:
php artisan list | grep lychee- 使用系统提示的替代命令(如
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