leomarriel / laravel-face-detector
Laravel 面部检测器
v1.0.0
2023-09-01 03:46 UTC
Requires
- php: ^8.0
- illuminate/support: ^10
README
一个用于在图像中处理面部检测的 Laravel 包
当前功能
- 读取本地或远程文件
- 外部 URL 支持
- 多种方式输出找到的面部
- 文件验证
安装
composer require leomarriel/laravel-face-detector
配置
没有自动发现的 Laravel
如果您不使用自动发现,请将 FaceDetectorServiceProvider
添加到 config/app.php
中的 providers 数组
'providers' => [ ... Leomarriel\FaceDetector\FaceDetectorServiceProvider::class, ... ],
将配置复制到您的项目中
php artisan vendor:publish --tag=facedetector-config
执行上述命令后,包配置将被发布到 config/facedetector.php
配置文件
有两组配置选项可用
config/facedetector.php
是一个关联数组,具有以下可能的键
disk
(字符串): 命令输出save()
保存文件时使用的存储磁盘。noFoundFaceException
(布尔值): 禁用未找到面部时的异常padding
(数组): 定义围绕找到的面部的填充
使用方法
直接使用,不使用外观:
您可以创建一个新的 FaceDetector
实例并加载本地或远程文件
use Leomarriel\FaceDetector\FaceDetector; $face = new FaceDetector(); $face->loadFile('path/to/image.jpg'); $face->preview();
如果您想使用外观进行面部检测,请将以下内容添加到 config/app.php
中的外观中
'aliases' => [ ... 'FaceDetector' => Leomarriel\FaceDetector\Facades\FaceDetector::class, ... ],
使用外观进行面部检测
目前有两种加载文件的方式
从路径
use FaceDetector; $face = FaceDetector::loadFile('path/to/image.jpg')->preview();
从 URL
use FaceDetector; $face = FaceDetector::loadUrl('https://url/to/image.jpg')->preview();
输出详细信息
检查所有可用的输出方式
use FaceDetector; $face = FaceDetector::loadFile('path/to/image.jpg');
$face->found(); // (bool) Return a boolean whether or not a face was found in the file
$face->face(); // (array) Return an array with the position of the found face
$face->preview(); // Return a preview of the face found with a tag
$face->json(); // Return the found face in json format
$face->stream(); // Return a response with found face cropped in JPG to show in browser
$face->output(); // Return a jpg string file with the found face
$face->save(); // Physically save the face found
保存详细信息
您可以使用 $face->save()
快速保存找到的面部输出。脚本将为您的文件创建一个唯一名称并将其存储在您的存储中的 facedetector
文件夹中。
$face->save(); // Physically save the face found on folder "facedetector" in your storage
您可以设置您首选的存储位置
$face->save('path/to/save'); // Physically save the found face with a random name in a defined path.
完全控制,设置要保存的存储路径和文件名。保存为 JPG 或 PNG,由您选择。
$face->save('path/to/save', 'new-image.jpg'); // Physically save the found face with a defined path and name.
如果保存成功,将返回以下数据
[ 'filename' => 'Saved file name', 'size' => 'file size after cropping', 'path' => 'path to file location relative to the disk storage', 'url' => 'public url to access the file in browser' ]
☕️ 买我一杯咖啡
我很高兴能够为您的项目做出贡献,如果这个包以任何方式帮助了您,您能否用一杯咖啡来回报我?拥抱!