Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Akeneo Rekognition Bundle Laravel Package

clickandmortar/akeneo-rekognition-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to First Use

  1. Install the Bundle

    composer require clickandmortar/akeneo-rekognition-bundle
    

    Ensure compatibility with your Akeneo version (e.g., v0.3.* for Akeneo v4.0.*).

  2. Enable the Bundle Add to config/bundles.php:

    ClickAndMortar\AkeneoRekognitionBundle\ClickAndMortarAkeneoRekognitionBundle::class => ['all' => true]
    
  3. Configure AWS Credentials Set AWS credentials in config/services/services.yml (or via environment variables):

    parameters:
        aws.access_key_id: '%env(AWS_ACCESS_KEY_ID)%'
        aws.secret_access_key: '%env(AWS_SECRET_ACCESS_KEY)%'
        aws.region: '%env(AWS_REGION)%'
    
  4. Trigger First Analysis Use the CLI command to process a product:

    php bin/console akeneo-rekognition:analyze --product-sku="PRODUCT_SKU"
    

    Verify results in the product’s rekognition_labels or rekognition_text attributes (if configured).


Implementation Patterns

Workflows

  1. Batch Processing Use the akeneo-rekognition:analyze:batch command to process multiple products via a CSV file:

    php bin/console akeneo-rekognition:analyze:batch --file="path/to/products.csv"
    
    • CSV Format: sku,image_path (e.g., PROD001,/path/to/image.jpg).
  2. Event-Driven Integration Subscribe to Akeneo’s product_update event to auto-trigger analysis:

    // src/EventListener/RekognitionListener.php
    use ClickAndMortar\AkeneoRekognitionBundle\Event\RekognitionEvent;
    
    class RekognitionListener {
        public function onProductUpdate(RekognitionEvent $event) {
            $product = $event->getProduct();
            if ($product->hasImage()) {
                $this->rekognitionService->analyze($product);
            }
        }
    }
    

    Register in services.yml:

    services:
        App\EventListener\RekognitionListener:
            tags:
                - { name: kernel.event_listener, event: akeneo_rekognition.analyze, method: onProductUpdate }
    
  3. Custom Attribute Mapping Extend the bundle to map Rekognition results to custom product attributes:

    # config/akeneo_rekognition.yml
    attributes:
        labels:
            - { attribute: "product_color", field: "color_name" }
        text:
            - { attribute: "product_description", field: "extracted_text" }
    

Integration Tips

  • Image Validation: Pre-check image URLs/paths for accessibility before analysis.
  • Rate Limiting: AWS Rekognition has usage limits. Implement retries with exponential backoff:
    $client = new \Aws\Rekognition\RekognitionClient([
        'region'  => 'us-east-1',
        'version' => 'latest',
        'retry'   => [
            'max_attempts' => 3,
            'mode'         => 'standard',
        ],
    ]);
    
  • Async Processing: Use Symfony Messenger or Akeneo’s queue system for large catalogs:
    $message = new AnalyzeProductMessage($product);
    $bus->dispatch($message);
    

Gotchas and Tips

Pitfalls

  1. AWS Credentials

    • Issue: Hardcoded credentials in services.yml expose security risks.
    • Fix: Use environment variables or AWS IAM roles (for EC2/ECS):
      parameters:
          aws.credentials.role_arn: '%env(AWS_IAM_ROLE_ARN)%'
      
  2. Image Format/Size

    • Issue: Rekognition requires images ≤ 5MB and specific formats (JPEG/PNG).
    • Fix: Validate and resize images before processing:
      use Intervention\Image\ImageManager;
      
      $image = (new ImageManager())->make($imagePath);
      $image->resize(1024, 1024)->save();
      
  3. Attribute Conflicts

    • Issue: Overwriting existing product attributes (e.g., description).
    • Fix: Use unique attribute names (e.g., rekognition_description) or merge logic:
      $product->setDescription(
          $product->getDescription() . "\n\nDetected: " . $rekognitionText
      );
      
  4. Deprecated Methods

    • Issue: Bundle uses rekognition-php v1.x (abandoned in 2020).
    • Fix: Fork the package or migrate to AWS SDK v3 directly:
      $result = $client->detectLabels(['Image' => ['S3Object' => ['Bucket' => 'bucket', 'Name' => 'image.jpg']]]);
      

Debugging

  • Enable Verbose Logging Add to config/packages/monolog.yaml:
    handlers:
        akeneo_rekognition:
            type: stream
            path: "%kernel.logs_dir%/akeneo_rekognition.log"
            level: debug
    
  • Test with Mocked AWS Use aws-sdk-mock for local testing:
    composer require aws/aws-sdk-php-mock
    
    use Aws\Rekognition\RekognitionClient;
    use Aws\Sdk\MockHandler;
    
    $mock = new MockHandler();
    $mock->append(new MockDetectLabels());
    $client = new RekognitionClient([], ['handler' => $mock]);
    

Extension Points

  1. Custom Analyzers Implement ClickAndMortar\AkeneoRekognitionBundle\Analyzer\AnalyzerInterface for additional AWS services (e.g., Celebrity Recognition):

    class CelebrityAnalyzer implements AnalyzerInterface {
        public function analyze($image): array {
            $result = $client->recognizeCelebrities(['Image' => ['Bytes' => file_get_contents($image)]]);
            return $result->getCelebrityFaces();
        }
    }
    

    Register in services.yml:

    services:
        App\Analyzer\CelebrityAnalyzer:
            tags:
                - { name: akeneo_rekognition.analyzer, type: "celebrity" }
    
  2. Post-Processing Filters Filter Rekognition results before storage (e.g., exclude "background" labels):

    // src/Service/RekognitionFilter.php
    class RekognitionFilter {
        public function filterLabels(array $labels): array {
            return array_filter($labels, fn($label) => $label['Name'] !== 'Background');
        }
    }
    

    Inject into the bundle’s service container.

  3. Database Storage Override default attribute storage to use a dedicated table:

    // src/Entity/RekognitionResult.php
    #[ORM\Entity]
    class RekognitionResult {
        #[ORM\Id, ORM\GeneratedValue]
        private ?int $id = null;
    
        #[ORM\ManyToOne(targetEntity: Product::class)]
        private ?Product $product = null;
    
        #[ORM\Column(type: 'json')]
        private array $labels = [];
    
        // ...
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver