tourze/risky-image-detect-bundle

提供风险图片检测和识别功能的 Symfony Bundle

Installs: 147

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/risky-image-detect-bundle

0.0.1 2025-04-20 20:33 UTC

This package is auto-updated.

Last update: 2025-11-01 19:23:44 UTC


README

English | 中文

Latest Version PHP Version Total Downloads License Coverage Status

A Symfony Bundle for detecting risky image content, providing a secure image validation service.

Features

  • Simple and extensible interface for risky image detection
  • Default implementation ready to use out of the box
  • Easy to customize with your own detection logic
  • Fully compatible with Symfony 6.4+ and PHP 8.1+
  • Comprehensive test coverage

Installation

Install this package using Composer:

composer require tourze/risky-image-detect-bundle

Configuration

Enable this bundle in your Symfony project:

// config/bundles.php
return [
    // ...
    Tourze\RiskyImageDetectBundle\RiskyImageDetectBundle::class => ['all' => true],
];

Quick Start

This bundle provides a RiskyImageDetector interface and its default implementation DefaultRiskyImageDetector for detecting risky image content.

<?php

use Tourze\RiskyImageDetectBundle\Service\RiskyImageDetector;

class ImageProcessingService
{
    public function __construct(
        private readonly RiskyImageDetector $riskyImageDetector
    ) {
    }
    
    public function processImage(string $imageData): void
    {
        if ($this->riskyImageDetector->isRiskyImage($imageData)) {
            // Handle risky image...
            throw new \Exception('Risky image detected');
        } else {
            // Process normal image...
            $this->processNormalImage($imageData);
        }
    }
    
    private function processNormalImage(string $imageData): void
    {
        // Your image processing logic here
    }
}

Customization

You can create your own RiskyImageDetector implementation and set it as the default using Symfony's service configuration:

// 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
    {
        // Your custom implementation...
        // For example, integrate with external API or use ML models
        return $this->checkWithExternalService($image);
    }
    
    private function checkWithExternalService(string $image): bool
    {
        // Implementation details...
        return false;
    }
}

Development

Run tests:

./vendor/bin/phpunit packages/risky-image-detect-bundle/tests

Run static analysis:

php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/risky-image-detect-bundle

License

This package is released under the MIT License. See LICENSE file for details.