tourze / risky-image-detect-bundle
风险图片识别服务
Installs: 38
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.1
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/event-dispatcher: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-05-09 16:08:31 UTC
README
这是一个Symfony Bundle,提供风险图片检测功能。
安装
使用Composer安装此包:
composer require tourze/risky-image-detect-bundle
配置
在您的Symfony项目中启用此Bundle:
// config/bundles.php return [ // ... Tourze\RiskyImageDetectBundle\RiskyImageDetectBundle::class => ['all' => true], ];
使用方法
此Bundle提供了一个 RiskyImageDetector
接口及其默认实现 DefaultRiskyImageDetector
,用于检测图片是否包含风险内容。
// 通过依赖注入使用 use Tourze\RiskyImageDetectBundle\Service\RiskyImageDetector; class YourService { public function __construct( private readonly RiskyImageDetector $riskyImageDetector ) { } public function processImage(string $imageData): void { if ($this->riskyImageDetector->isRiskyImage($imageData)) { // 处理风险图片... } else { // 处理正常图片... } } }
自定义实现
您可以创建自己的 RiskyImageDetector
实现,并使用Symfony的服务配置将其设置为默认实现:
// src/Service/CustomRiskyImageDetector.php namespace App\Service; use Symfony\Component\DependencyInjection\Attribute\AsAlias; use Tourze\RiskyImageDetectBundle\Service\RiskyImageDetector; #[AsAlias(RiskyImageDetector::class)] class CustomRiskyImageDetector implements RiskyImageDetector { public function isRiskyImage(string $image): bool { // 您的自定义实现... } }
开发
运行测试:
./vendor/bin/phpunit packages/risky-image-detect-bundle/tests
许可证
本包基于MIT许可证发布。详情请参阅LICENSE文件。