Hello,
I’m a bit confused at the moment. I’d like to implement a processor that hooks into the image generation. From the original images, for example, images in different sizes and various crops are created.
Once that is done, I’d like to hook into the process. The hooking works quite well with:
What I don’t understand, however, is the task workflow. I receive a TaskInterface with a SourceFile and a TargetFile.
I suppose it would be unwise to manipulate the source file, so I take the path from the TargetFile and save my result under
$processingPath = $targetFile->getForLocalProcessing(true);
Then I thought I needed to call
$targetFile->updateWithLocalFile($processingPath);
BUT that doesn’t work because of the identifier, which I can’t set—why is that?
public function updateWithLocalFile(string $filePath): void
{
if (empty($this->identifier)) {
throw new \RuntimeException('Cannot update original file!', 1350582054);
}
}
Have I possibly completely misunderstood the process? Or is it just a small detail…
Thanks in advance for any helpful answers…
Clemens
Here is my Coding:
/**
* Processes the given task and sets the processing result in the task object.
*/
public function processTask(TaskInterface $task): void
{
$watermarkUids = $this->get_category_watermark_file_uids($task->getSourceFile());
$wm = $this->fileRepository->findByUid($watermarkUids[0]['uid_local']);
$this->addWatermark($task->getSourceFile(), $task->getTargetFile(), $wm, 'test.jpg');
}
private function addWatermark(
ProcessedFile|File $sourceFile,
ProcessedFile|File $targetFile,
File $watermarkFile,
string $targetImagePath
): void {
$background = $this->create_image($targetFile);
$watermark = $this->create_image($watermarkFile);
$bgWidth = imagesx($background);
$bgHeight = imagesy($background);
$wmWidth = imagesx($watermark);
$wmHeight = imagesy($watermark);
$padding = 10;
$posX = $bgWidth - $wmWidth - $padding;
$posY = $bgHeight - $wmHeight - $padding;
imagecopy($background, $watermark, $posX, $posY, 0, 0, $wmWidth, $wmHeight);
$processingPath = $targetFile->getForLocalProcessing(true);
imagejpeg($background, $processingPath, 90); // 90 = JPEG-Qualität
imagedestroy($background);
imagedestroy($watermark);
$targetFile->updateWithLocalFile($processingPath);
}