<?php
namespace Jabber\GenericBundle\EventListener;
use Pimcore\Model\DataObject;
use Pimcore\Model\Asset;
use Pimcore\Model\DataObject\Product;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Event\Model\DataObjectEvent;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Process\Process;
class NewThumbnails {
public $redis;
public $parameterBag;
public function __construct(ParameterBagInterface $parameterBag) {
$this->parameterBag = $parameterBag;
}
public function onImageCreated(GenericEvent $e) {
$fileName = $e->getSubject()->getAsset()->getFilename();
if ($e->getSubject()->getAsset()->getFilename() && preg_match('@\.CR2z?$@', $e->getSubject()->getAsset()->getFilename())) {
$pathReferences = $e->getSubject()->getPathReference();
if ($pathReferences['storagePath']) {
$thumbnailFile = "\"" . PIMCORE_WEB_ROOT . '/var/tmp/nasthumbnails' . $pathReferences['storagePath'] . "\"";
if ($e->getSubject()->getConfig()->getName() == "DAM") {
$this->redis = new \Redis();
$this->redis->connect('127.0.0.1', 6379);
$this->redis->sAdd('pimcore_thumbnails_whitebalance_queue', "\"" . PIMCORE_WEB_ROOT . '/var/tmp/nasthumbnails' . $pathReferences['storagePath'] . "\"");
}
}
} else if ($e->getSubject()->getConfig()->getName() == "Next" || $e->getSubject()->getConfig()->getName() == "next-dynamic" || $e->getSubject()->getConfig()->getName() == "mands-dynamic") {
$thumbnailConfig = $e->getSubject()->getConfig();
$pathReferences = $e->getSubject()->getPathReference();
if ($pathReferences['storagePath']) {
$thumbnailFile = "\"" . PIMCORE_WEB_ROOT . '/var/tmp/nasthumbnails' . $pathReferences['storagePath'] . "\"";
$exiftool = \Pimcore\Tool\Console::getExecutable('exiftool');
if ($exiftool) {
$dpi = 300;
$process = new Process([$exiftool, '-overwrite_original', '-xresolution=' . $dpi, '-yresolution=' . $dpi, '-resolutionunit=inches', $thumbnailFile]);
$result = $process->run();
}
}
}
}
}