Skip to content

Commit

Permalink
task: drop collage constants (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott authored Nov 5, 2023
1 parent 7e8fc51 commit 9899ed5
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 137 deletions.
2 changes: 1 addition & 1 deletion api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
if ($isCollage) {
list($collageSrcImagePaths, $srcImages) = Collage::getCollageFiles($config['collage'], $filename_tmp, $file, $srcImages);

if (!Collage::createCollage($collageSrcImagePaths, $filename_tmp, $image_filter)) {
if (!Collage::createCollage($config, $collageSrcImagePaths, $filename_tmp, $image_filter)) {
throw new Exception('Error creating collage image.');
}
}
Expand Down
6 changes: 3 additions & 3 deletions api/applyVideoEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Photobooth\DatabaseManager;
use Photobooth\Collage;
use Photobooth\CollageConfig;
use Photobooth\Factory\CollageConfigFactory;
use Photobooth\Image;
use Photobooth\Service\LoggerService;

Expand Down Expand Up @@ -63,11 +63,11 @@
$images = [];
if ($config['video']['collage'] && count($frames) === 4) {
$collageFilename = sprintf('%s-collage.jpg', $file);
$collageConfig = new CollageConfig();
$collageConfig = CollageConfigFactory::fromConfig($config);
$collageConfig->collageLayout = '2x4-3';
$collageConfig->collageTakeFrame = 'off';
$collageConfig->collagePlaceholder = false;
if (!Collage::createCollage($frames, $collageFilename, $config['filters']['defaults'], $collageConfig)) {
if (!Collage::createCollage($config, $frames, $collageFilename, $config['filters']['defaults'], $collageConfig)) {
throw new Exception('Could not create collage.');
}
$images[] = $collageFilename;
Expand Down
41 changes: 0 additions & 41 deletions lib/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Photobooth\Service\LanguageService;
use Photobooth\Service\LoggerService;
use Photobooth\Service\PrintManagerService;
use Photobooth\Utility\PathUtility;

session_start();

Expand Down Expand Up @@ -56,43 +55,3 @@
define('DB_FILE', $config['foldersAbs']['data'] . DIRECTORY_SEPARATOR . $config['database']['file'] . '.txt');
define('MAIL_FILE', $config['foldersAbs']['data'] . DIRECTORY_SEPARATOR . $config['mail']['file'] . '.txt');
define('IMG_DIR', $config['foldersAbs']['images']);

// Collage Config
define('COLLAGE_LAYOUT', $config['collage']['layout']);
define('COLLAGE_RESOLUTION', (int) substr($config['collage']['resolution'], 0, -3));
define('COLLAGE_BACKGROUND_COLOR', $config['collage']['background_color']);
define('COLLAGE_FRAME', str_starts_with($config['collage']['frame'], 'http') ? $config['collage']['frame'] : $_SERVER['DOCUMENT_ROOT'] . $config['collage']['frame']);
define(
'COLLAGE_BACKGROUND',
(empty($config['collage']['background'])
? ''
: str_starts_with($config['collage']['background'], 'http'))
? $config['collage']['background']
: $_SERVER['DOCUMENT_ROOT'] . $config['collage']['background']
);
define('COLLAGE_TAKE_FRAME', $config['collage']['take_frame']);
define('COLLAGE_PLACEHOLDER', $config['collage']['placeholder']);
// If a placeholder is set, decrease the value by 1 in order to reflect array counting at 0
define('COLLAGE_PLACEHOLDER_POSITION', (int) $config['collage']['placeholderposition'] - 1);
define(
'COLLAGE_PLACEHOLDER_PATH',
str_starts_with($config['collage']['placeholderpath'], 'http') ? $config['collage']['placeholderpath'] : $_SERVER['DOCUMENT_ROOT'] . $config['collage']['placeholderpath']
);
define('COLLAGE_DASHEDLINE_COLOR', $config['collage']['dashedline_color']);
// If a placholder image should be used, we need to increase the limit here in order to count the images correct
define('COLLAGE_LIMIT', $config['collage']['placeholder'] ? $config['collage']['limit'] + 1 : $config['collage']['limit']);
define('PICTURE_FLIP', $config['picture']['flip']);
define('PICTURE_ROTATION', $config['picture']['rotation']);
define('PICTURE_POLAROID_EFFECT', $config['picture']['polaroid_effect'] === true ? 'enabled' : 'disabled');
define('PICTURE_POLAROID_ROTATION', $config['picture']['polaroid_rotation']);
define('TEXTONCOLLAGE_ENABLED', $config['textoncollage']['enabled'] === true ? 'enabled' : 'disabled');
define('TEXTONCOLLAGE_LINE1', $config['textoncollage']['line1']);
define('TEXTONCOLLAGE_LINE2', $config['textoncollage']['line2']);
define('TEXTONCOLLAGE_LINE3', $config['textoncollage']['line3']);
define('TEXTONCOLLAGE_LOCATIONX', $config['textoncollage']['locationx']);
define('TEXTONCOLLAGE_LOCATIONY', $config['textoncollage']['locationy']);
define('TEXTONCOLLAGE_ROTATION', $config['textoncollage']['rotation']);
define('TEXTONCOLLAGE_FONT', PathUtility::getAbsolutePath($config['textoncollage']['font']));
define('TEXTONCOLLAGE_FONT_COLOR', $config['textoncollage']['font_color']);
define('TEXTONCOLLAGE_FONT_SIZE', $config['textoncollage']['font_size']);
define('TEXTONCOLLAGE_LINESPACE', $config['textoncollage']['linespace']);
8 changes: 5 additions & 3 deletions src/Collage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

namespace Photobooth;

use Photobooth\Dto\CollageConfig;
use Photobooth\Enum\ImageFilterEnum;
use Photobooth\Factory\CollageConfigFactory;
use Photobooth\Utility\ImageUtility;
use Photobooth\Utility\PathUtility;

class Collage
{
public static function createCollage($srcImagePaths, $destImagePath, $filter = 'plain', CollageConfig $c = null)
public static function createCollage(array $config, $srcImagePaths, $destImagePath, $filter = 'plain', CollageConfig $c = null)
{
if (is_null($c)) {
$c = new CollageConfig();
if ($c === null) {
$c = CollageConfigFactory::fromConfig($config);
}
$editImages = [];
$rotate_after_creation = false;
Expand Down
89 changes: 0 additions & 89 deletions src/CollageConfig.php

This file was deleted.

33 changes: 33 additions & 0 deletions src/Dto/CollageConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Photobooth\Dto;

class CollageConfig
{
public string $collageLayout;
public int $collageResolution;
public string $collageBackgroundColor;
public string $collageFrame;
public string $collageTakeFrame;
public string $collagePlaceholder;
public int $collagePlaceholderPosition;
public string $collagePlaceholderPath;
public string $collageBackground;
public string $collageDashedLineColor;
public int $collageLimit;
public string $pictureFlip;
public int $pictureRotation;
public string $picturePolaroidEffect;
public int $picturePolaroidRotation;
public string $textOnCollageEnabled;
public string $textOnCollageLine1;
public string $textOnCollageLine2;
public string $textOnCollageLine3;
public int $textOnCollageLocationX;
public int $textOnCollageLocationY;
public int $textOnCollageRotation;
public string $textOnCollageFont;
public string $textOnCollageFontColor;
public int $textOnCollageFontSize;
public int $textOnCollageLinespace;
}
52 changes: 52 additions & 0 deletions src/Factory/CollageConfigFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Photobooth\Factory;

use Photobooth\Dto\CollageConfig;
use Photobooth\Utility\PathUtility;

class CollageConfigFactory
{
public static function fromConfig(array $config): CollageConfig
{
$collageConfig = new CollageConfig();
$collageConfig->collageLayout = $config['collage']['layout'];
$collageConfig->collageResolution = (int) substr($config['collage']['resolution'], 0, -3);
$collageConfig->collageBackgroundColor = $config['collage']['background_color'];
$collageConfig->collageFrame = str_starts_with($config['collage']['frame'], 'http')
? $config['collage']['frame']
: $_SERVER['DOCUMENT_ROOT'] . $config['collage']['frame'];
$collageConfig->collageTakeFrame = $config['collage']['take_frame'];
$collageConfig->collagePlaceholder = $config['collage']['placeholder'];
// If a placeholder is set, decrease the value by 1 in order to reflect array counting at 0
$collageConfig->collagePlaceholderPosition = (int) $config['collage']['placeholderposition'] - 1;
$collageConfig->collagePlaceholderPath = str_starts_with($config['collage']['placeholderpath'], 'http')
? $config['collage']['placeholderpath']
: $_SERVER['DOCUMENT_ROOT'] . $config['collage']['placeholderpath'];
$collageConfig->collageBackground = (empty($config['collage']['background'])
? ''
: str_starts_with($config['collage']['background'], 'http'))
? $config['collage']['background']
: $_SERVER['DOCUMENT_ROOT'] . $config['collage']['background'];
$collageConfig->collageDashedLineColor = $config['collage']['dashedline_color'];
// If a placholder image should be used, we need to increase the limit here in order to count the images correct
$collageConfig->collageLimit = (int) ($config['collage']['placeholder'] ? $config['collage']['limit'] + 1 : $config['collage']['limit']);
$collageConfig->pictureFlip = $config['picture']['flip'];
$collageConfig->pictureRotation = (int) $config['picture']['rotation'];
$collageConfig->picturePolaroidEffect = $config['picture']['polaroid_effect'] === true ? 'enabled' : 'disabled';
$collageConfig->picturePolaroidRotation = (int) $config['picture']['polaroid_rotation'];
$collageConfig->textOnCollageEnabled = $config['textoncollage']['enabled'] === true ? 'enabled' : 'disabled';
$collageConfig->textOnCollageLine1 = $config['textoncollage']['line1'];
$collageConfig->textOnCollageLine2 = $config['textoncollage']['line2'];
$collageConfig->textOnCollageLine3 = $config['textoncollage']['line3'];
$collageConfig->textOnCollageLocationX = (int) $config['textoncollage']['locationx'];
$collageConfig->textOnCollageLocationY = (int) $config['textoncollage']['locationy'];
$collageConfig->textOnCollageRotation = (int) $config['textoncollage']['rotation'];
$collageConfig->textOnCollageFont = PathUtility::getAbsolutePath($config['textoncollage']['font']);
$collageConfig->textOnCollageFontColor = $config['textoncollage']['font_color'];
$collageConfig->textOnCollageFontSize = (int) $config['textoncollage']['font_size'];
$collageConfig->textOnCollageLinespace = (int) $config['textoncollage']['linespace'];

return $collageConfig;
}
}

0 comments on commit 9899ed5

Please sign in to comment.