/** * Processing the focus point crop (fallback to LocalCropScaleMaskHelper) * * @param TaskInterface $task * * @return array|NULL */ public function process(TaskInterface $task) { $configuration = $task->getConfiguration(); $crop = $configuration['crop'] ? json_decode($configuration['crop']) : null; if ($crop instanceof \stdClass && isset($crop->x)) { // if crop is enable release the process return parent::process($task); } $sourceFile = $task->getSourceFile(); try { if (self::$deepCheck === false) { self::$deepCheck = true; $ratio = $this->getCurrentRatioConfiguration(); $this->dimensionService->getRatio($ratio); $newFile = $this->focusCropService->getCroppedImageSrcByFile($sourceFile, $ratio); $file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($newFile); $targetFile = $task->getTargetFile(); ObjectAccess::setProperty($targetFile, 'originalFile', $file, true); ObjectAccess::setProperty($targetFile, 'originalFileSha1', $file->getSha1(), true); ObjectAccess::setProperty($targetFile, 'storage', $file->getStorage(), true); ObjectAccess::setProperty($task, 'sourceFile', $file, true); ObjectAccess::setProperty($task, 'targetFile', $targetFile, true); } } catch (\Exception $ex) { } self::$deepCheck = false; return parent::process($task); }
/** * Processing the focus point crop (fallback to LocalCropScaleMaskHelper) * * @param TaskInterface $task * * @return array|NULL */ public function process(TaskInterface $task) { $sourceFile = $task->getSourceFile(); try { $ratio = $this->getCurrentRatioConfiguration(); $this->dimensionService->getRatio($ratio); $newFile = $this->focusCropService->getCroppedImageSrcByFile($sourceFile, $ratio); $file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($newFile); $targetFile = $task->getTargetFile(); ObjectAccess::setProperty($targetFile, 'originalFile', $file, TRUE); ObjectAccess::setProperty($targetFile, 'originalFileSha1', $file->getSha1(), TRUE); ObjectAccess::setProperty($targetFile, 'storage', $file->getStorage(), TRUE); ObjectAccess::setProperty($task, 'sourceFile', $file, TRUE); ObjectAccess::setProperty($task, 'targetFile', $targetFile, TRUE); } catch (\Exception $ex) { } return parent::process($task); }
/** * @test */ public function testValidRatio() { $this->assertEquals([1, 1], $this->service->getRatio('1:1')); $this->assertEquals([16, 9], $this->service->getRatio('16:9')); $this->assertEquals([4, 2], $this->service->getRatio('4:3')); }
/** * @test */ public function testValidRatio() { $this->assertEquals(array(1, 1), $this->service->getRatio('1:1')); $this->assertEquals(array(16, 9), $this->service->getRatio('16:9')); $this->assertEquals(array(4, 2), $this->service->getRatio('4:3')); }