clickandmortar/akeneo-rekognition-bundle
Install the Bundle
composer require clickandmortar/akeneo-rekognition-bundle
Ensure compatibility with your Akeneo version (e.g., v0.3.* for Akeneo v4.0.*).
Enable the Bundle
Add to config/bundles.php:
ClickAndMortar\AkeneoRekognitionBundle\ClickAndMortarAkeneoRekognitionBundle::class => ['all' => true]
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)%'
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).
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"
sku,image_path (e.g., PROD001,/path/to/image.jpg).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 }
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" }
$client = new \Aws\Rekognition\RekognitionClient([
'region' => 'us-east-1',
'version' => 'latest',
'retry' => [
'max_attempts' => 3,
'mode' => 'standard',
],
]);
$message = new AnalyzeProductMessage($product);
$bus->dispatch($message);
AWS Credentials
services.yml expose security risks.parameters:
aws.credentials.role_arn: '%env(AWS_IAM_ROLE_ARN)%'
Image Format/Size
use Intervention\Image\ImageManager;
$image = (new ImageManager())->make($imagePath);
$image->resize(1024, 1024)->save();
Attribute Conflicts
description).rekognition_description) or merge logic:
$product->setDescription(
$product->getDescription() . "\n\nDetected: " . $rekognitionText
);
Deprecated Methods
rekognition-php v1.x (abandoned in 2020).$result = $client->detectLabels(['Image' => ['S3Object' => ['Bucket' => 'bucket', 'Name' => 'image.jpg']]]);
config/packages/monolog.yaml:
handlers:
akeneo_rekognition:
type: stream
path: "%kernel.logs_dir%/akeneo_rekognition.log"
level: debug
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]);
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" }
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.
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 = [];
// ...
}
How can I help you explore Laravel packages today?