Skip to content

Commit

Permalink
test (Collage): use ImageProcessor if exist
Browse files Browse the repository at this point in the history
Change-Id: If08beb247219d80e5a168d023237b2a1ac0e5a21
  • Loading branch information
andi34 committed Nov 16, 2024
1 parent 79f6304 commit 363ddc9
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions test/collage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
require_once '../lib/boot.php';

use Photobooth\Collage;
use Photobooth\Image;
use Photobooth\Enum\FolderEnum;
use Photobooth\Processor\ImageProcessor;
use Photobooth\Utility\ImageUtility;
use Photobooth\Utility\PathUtility;
use Photobooth\Service\ApplicationService;
Expand All @@ -15,27 +17,53 @@

$languageService = LanguageService::getInstance();
$errorMessage = '';
$database = null;
$processor = null;

try {
$demoImages = ImageUtility::getDemoImages($config['collage']['limit']);
$vars['fileName'] = date('Ymd_His') . '.jpg';
$vars['style'] = 'collage';
$vars['imageFilter'] = $config['filters']['defaults'];
$vars['isCollage'] = true;
$vars['editSingleCollage'] = false;
$vars['isChroma'] = false;
$vars['srcImages'] = [];
$vars['srcImages'][] = $vars['fileName'];
$vars['singleImageFile'] = $vars['fileName'];
$vars['tmpFile'] = FolderEnum::TEST->absolute() . DIRECTORY_SEPARATOR . $vars['fileName'];
$vars['resultFile'] = $vars['tmpFile'];

$imageHandler = new Image();
$imageHandler->debugLevel = $config['dev']['loglevel'];
$imageHandler->imageModified = false;

$name = date('Ymd_His') . '.jpg';
$collageSrcImagePaths = [];
if (class_exists('Photobooth\Processor\ImageProcessor')) {
$processor = new ImageProcessor($imageHandler, $logger, $database, $vars, $config);
}

$demoImages = ImageUtility::getDemoImages($config['collage']['limit']);
for ($i = 0; $i < $config['collage']['limit']; $i++) {
$image = $demoImages[$i];
$path = FolderEnum::TEMP->absolute() . DIRECTORY_SEPARATOR . $i . '_' . $name;
$path = FolderEnum::TEMP->absolute() . DIRECTORY_SEPARATOR . $i . '_' . $vars['fileName'];
if (!copy($image, $path)) {
throw new \Exception('Failed to copy image.');
}
$collageSrcImagePaths[] = $path;
$vars['collageSrcImagePaths'][] = $path;
}

$filename_tmp = FolderEnum::TEST->absolute() . DIRECTORY_SEPARATOR . $name;
if (Collage::createCollage($config, $collageSrcImagePaths, $filename_tmp, $config['filters']['defaults'])) {
if ($processor !== null && $processor instanceof ImageProcessor && method_exists($processor, 'preCollageProcessing')) {
list($imageHandler, $vars, $config) = $processor->preCollageProcessing($imageHandler, $vars, $config);
}

if (Collage::createCollage($config, $vars['collageSrcImagePaths'], $vars['tmpFile'], $vars['imageFilter'])) {
for ($k = 0; $k < $config['collage']['limit']; $k++) {
unlink($collageSrcImagePaths[$k]);
unlink($vars['collageSrcImagePaths'][$k]);
}
}

if ($processor !== null && $processor instanceof ImageProcessor && method_exists($processor, 'postCollageProcessing')) {
list($imageHandler, $vars, $config) = $processor->postCollageProcessing($imageHandler, $vars, $config);
}
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
$logger->error($errorMessage);
Expand All @@ -55,7 +83,7 @@
<?php
if (empty($errorMessage)) {
echo '<div class="border border-solid border-black">';
echo '<img src="' . PathUtility::getPublicPath($filename_tmp) . '" alt="Test Image">';
echo '<img src="' . PathUtility::getPublicPath($vars['tmpFile']) . '" alt="Test Image">';
echo '</div>';
} else {
echo '<div class="flex flex-col gap-2">';
Expand Down

0 comments on commit 363ddc9

Please sign in to comment.