Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require_once '../lib/polaroid.php';
require_once '../lib/resize.php';
require_once '../lib/collage.php';
require_once '../lib/applyText.php';

if (!extension_loaded('gd')) {
die(
Expand Down Expand Up @@ -35,6 +36,18 @@
$thumb_size = substr($config['picture']['thumb_size'], 0, -2);
$chroma_size = substr($config['keying']['size'], 0, -2);

// text on picture variables
$fontpath = $config['textonpicture']['font'];
$fontcolor = $config['textonpicture']['font_color'];
$fontsize = $config['textonpicture']['font_size'];
$fontlocx = $config['textonpicture']['locationx'];
$fontlocy = $config['textonpicture']['locationy'];
$linespacing = $config['textonpicture']['linespace'];
$fontrot = $config['textonpicture']['rotation'];
$line1text = $config['textonpicture']['line1'];
$line2text = $config['textonpicture']['line2'];
$line3text = $config['textonpicture']['line3'];

if (!isset($_POST['style'])) {
die(
json_encode([
Expand Down Expand Up @@ -62,6 +75,24 @@
}
}

if ($config['textoncollage']['enabled']) {
if (is_dir(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . TEXTONCOLLAGE_FONT))) {
die(
json_encode([
'error' => 'Font not set! ' . TEXTONCOLLAGE_FONT . ' is a path but needs to be a ttf!',
])
);
}

if (!file_exists(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . TEXTONCOLLAGE_FONT))) {
die(
json_encode([
'error' => 'Font ' . TEXTONCOLLAGE_FONT . ' does not exist!',
])
);
}
}

$collageBasename = substr($filename_tmp, 0, -4);
$collageSrcImagePaths = [];

Expand Down Expand Up @@ -110,6 +141,24 @@
}
}

if ($config['textonpicture']['enabled']) {
if (is_dir(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $fontpath))) {
die(
json_encode([
'error' => 'Font not set! ' . $fontpath . ' is a path but needs to be a ttf!',
])
);
}

if (!file_exists(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $fontpath))) {
die(
json_encode([
'error' => 'Font ' . $fontpath . ' does not exist!',
])
);
}
}

// Only jpg/jpeg are supported
$imginfo = getimagesize($filename_tmp);
$mimetype = $imginfo['mime'];
Expand Down Expand Up @@ -189,6 +238,14 @@
imagedestroy($chromaCopyResource);
}

if ($config['textonpicture']['enabled'] && $_POST['style'] !== 'collage') {
imagejpeg($imageResource, $filename_photo, $config['jpeg_quality']['image']);
imagedestroy($imageResource);
ApplyText($filename_photo, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolor, $fontpath, $line1text, $line2text, $line3text, $linespacing);
$imageModified = true;
$imageResource = imagecreatefromjpeg($filename_photo);
}

// image scale, create thumbnail
$thumbResource = resizeImage($imageResource, $thumb_size, $thumb_size);

Expand Down
34 changes: 12 additions & 22 deletions api/print.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_once '../lib/db.php';
require_once '../lib/resize.php';
require_once '../lib/applyFrame.php';
require_once '../lib/applyText.php';

if (empty($_GET['filename'])) {
die(
Expand Down Expand Up @@ -49,7 +50,8 @@
}

// text on print variables
$fontpath = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['textonprint']['font']);
$fontpath = $config['textonprint']['font'];
$fontcolor = $config['textonprint']['font_color'];
$fontsize = $config['textonprint']['font_size'];
$fontlocx = $config['textonprint']['locationx'];
$fontlocy = $config['textonprint']['locationy'];
Expand Down Expand Up @@ -81,18 +83,18 @@
}

if ($config['textonprint']['enabled']) {
if (is_dir($fontpath)) {
if (is_dir(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $fontpath))) {
die(
json_encode([
'error' => 'Frame not set! ' . $fontpath . ' is a path but needs to be a png!',
'error' => 'Font not set! ' . $fontpath . ' is a path but needs to be a ttf!',
])
);
}

if (!file_exists($fontpath)) {
if (!file_exists(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $fontpath))) {
die(
json_encode([
'error' => 'Frame ' . $fontpath . ' does not exist!',
'error' => 'Font ' . $fontpath . ' does not exist!',
])
);
}
Expand Down Expand Up @@ -137,14 +139,6 @@
imagefill($print, 0, 0, imagecolorallocate($print, 255, 255, 255));
imagecopy($print, $source, 0, 0, 0, 0, $width, $height);
imagecopyresized($print, $code, $width, 0, 0, 0, $height / 2, $height / 2, imagesx($code), imagesy($code));

if ($config['textonprint']['enabled']) {
$fontcolour = imagecolorallocate($print, 0, 0, 0); // colour of font
imagettftext($print, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolour, $fontpath, $line1text);
imagettftext($print, $fontsize, $fontrot, $fontlocx, $fontlocy + $linespacing, $fontcolour, $fontpath, $line2text);
imagettftext($print, $fontsize, $fontrot, $fontlocx, $fontlocy + $linespacing * 2, $fontcolour, $fontpath, $line3text);
}

imagejpeg($print, $filename_print, $quality);
imagedestroy($code);
imagedestroy($source);
Expand All @@ -153,16 +147,12 @@
if ($config['print']['print_frame'] && !$config['picture']['take_frame']) {
ApplyFrame($filename_print, $filename_print, $print_frame);
}
}

if ($config['textonprint']['enabled']) {
$print = imagecreatefromjpeg($filename_print);
$fontcolour = imagecolorallocate($print, 0, 0, 0); // colour of font
imagettftext($print, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolour, $fontpath, $line1text);
imagettftext($print, $fontsize, $fontrot, $fontlocx, $fontlocy + $linespacing, $fontcolour, $fontpath, $line2text);
imagettftext($print, $fontsize, $fontrot, $fontlocx, $fontlocy + $linespacing * 2, $fontcolour, $fontpath, $line3text);
imagejpeg($print, $filename_print, $quality);
imagedestroy($print);
}
if ($config['textonprint']['enabled']) {
$print = imagecreatefromjpeg($filename_print);
ApplyText($filename_print, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolor, $fontpath, $line1text, $line2text, $line3text, $linespacing);
imagedestroy($print);
}

if ($config['print']['crop']) {
Expand Down
28 changes: 27 additions & 1 deletion config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
$config['picture']['keep_original'] = true;
$config['picture']['preserve_exif_data'] = false;
$config['picture']['allow_delete'] = true;
$config['textonpicture']['enabled'] = false;
$config['textonpicture']['line1'] = 'line 1';
$config['textonpicture']['line2'] = 'line 2';
$config['textonpicture']['line3'] = 'line 3';
$config['textonpicture']['locationx'] = '80';
$config['textonpicture']['locationy'] = '80';
$config['textonpicture']['rotation'] = '0';
$config['textonpicture']['font'] = 'resources/fonts/GreatVibes-Regular.ttf';
// possible font_color values: 'white', 'grey', 'black'
$config['textonpicture']['font_color'] = 'white';
$config['textonpicture']['font_size'] = '80';
$config['textonpicture']['linespace'] = '90';


// C O L L A G E
Expand All @@ -77,13 +89,25 @@
$config['collage']['cntdwn_time'] = '3';
$config['collage']['continuous'] = true;
// possible layout values: '2x2', '2x2-2', '2x4', '2x4-2', '1+3', '1+2'
$config['collage']['layout'] = '2x2';
$config['collage']['layout'] = '2x2-2';
// specify key id (e.g. 13 is the enter key) to use that key to take a collage (collage key)
// use for example https://keycode.info to get the key code
$config['collage']['key'] = null;
// possible take_frame values: 'off', 'always', 'once'
$config['collage']['take_frame'] = 'off';
$config['collage']['frame'] = 'resources/img/frames/frame.png';
$config['textoncollage']['enabled'] = true;
$config['textoncollage']['line1'] = 'Photobooth';
$config['textoncollage']['line2'] = ' we love';
$config['textoncollage']['line3'] = 'OpenSource';
$config['textoncollage']['locationx'] = '1470';
$config['textoncollage']['locationy'] = '250';
$config['textoncollage']['rotation'] = '0';
$config['textoncollage']['font'] = 'resources/fonts/GreatVibes-Regular.ttf';
// possible font_color values: 'white', 'grey', 'black'
$config['textoncollage']['font_color'] = 'black';
$config['textoncollage']['font_size'] = '50';
$config['textoncollage']['linespace'] = '90';
// DO NOT CHANGE limit here
$config['collage']['limit'] = NULL;

Expand Down Expand Up @@ -168,6 +192,8 @@
$config['textonprint']['locationy'] = '1050';
$config['textonprint']['rotation'] = '40';
$config['textonprint']['font'] = 'resources/fonts/GreatVibes-Regular.ttf';
// possible font_color values: 'white', 'grey', 'black'
$config['textonprint']['font_color'] = 'black';
$config['textonprint']['font_size'] = '100';
$config['textonprint']['linespace'] = '100';

Expand Down
33 changes: 33 additions & 0 deletions lib/applyText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

function ApplyText($srcImagePath, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolor, $fontpath, $line1text, $line2text, $line3text, $linespacing) {
$quality = 100;
$font = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $fontpath);
$image = imagecreatefromjpeg($srcImagePath);
if ($fontcolor === 'white') {
$color = imagecolorallocate($image, 255, 255, 255);
} elseif ($fontcolor === 'grey') {
$color = imagecolorallocate($image, 128, 128, 128);
} else {
$color = imagecolorallocate($image, 0, 0, 0);
}
if (!empty($line1text)) {
imagettftext($image, $fontsize, $fontrot, $fontlocx, $fontlocy, $color, $font, $line1text);
}
if (!empty($line2text)) {
if ($fontrot < 45 && $fontrot > -45) {
imagettftext($image, $fontsize, $fontrot, $fontlocx, $fontlocy + $linespacing, $color, $font, $line2text);
} else {
imagettftext($image, $fontsize, $fontrot, $fontlocx + $linespacing, $fontlocy, $color, $font, $line2text);
}
}
if (!empty($line3text)) {
if ($fontrot < 45 && $fontrot > -45) {
imagettftext($image, $fontsize, $fontrot, $fontlocx, $fontlocy + $linespacing * 2, $color, $font, $line3text);
} else {
imagettftext($image, $fontsize, $fontrot, $fontlocx + $linespacing * 2, $fontlocy, $color, $font, $line3text);
}
}
imagejpeg($image, $srcImagePath, $quality);
imagedestroy($image);
}
31 changes: 30 additions & 1 deletion lib/collage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/resize.php';
require_once __DIR__ . '/applyFrame.php';
require_once __DIR__ . '/applyText.php';

define('COLLAGE_LAYOUT', $config['collage']['layout']);
define('COLLAGE_FRAME', realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $config['collage']['frame']));
define('COLLAGE_TAKE_FRAME', $config['collage']['take_frame']);
define('COLLAGE_LIMIT', $config['collage']['limit']);
define('PICTURE_KEEP_ORIGINAL', $config['picture']['keep_original'] === true ? 'keep' : 'discard');
define('PICTURE_FLIP', $config['picture']['flip']);
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', $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']);

function createCollage($srcImagePaths, $destImagePath) {
if (!is_array($srcImagePaths) || count($srcImagePaths) !== COLLAGE_LIMIT) {
Expand Down Expand Up @@ -395,12 +407,29 @@ function createCollage($srcImagePaths, $destImagePath) {
}

imagejpeg($my_collage, $destImagePath, $quality); // Transfer image to destImagePath with returns the image to core
imagedestroy($my_collage); // Destroy the created collage in memory

if (COLLAGE_TAKE_FRAME === 'once') {
ApplyFrame($destImagePath, $destImagePath, COLLAGE_FRAME);
}

if (TEXTONCOLLAGE_ENABLED === 'enabled') {
ApplyText(
$destImagePath,
TEXTONCOLLAGE_FONT_SIZE,
TEXTONCOLLAGE_ROTATION,
TEXTONCOLLAGE_LOCATIONX,
TEXTONCOLLAGE_LOCATIONY,
TEXTONCOLLAGE_FONT_COLOR,
TEXTONCOLLAGE_FONT,
TEXTONCOLLAGE_LINE1,
TEXTONCOLLAGE_LINE2,
TEXTONCOLLAGE_LINE3,
TEXTONCOLLAGE_LINESPACE
);
}

imagedestroy($my_collage); // Destroy the created collage in memory

// Rotate image if needed
if ($rotate_after_creation) {
$tempRotatedImage = imagecreatefromjpeg($destImagePath);
Expand Down
Loading