forked from andreknieriem/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.php
More file actions
131 lines (113 loc) · 5.34 KB
/
print.php
File metadata and controls
131 lines (113 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
$my_config = 'my.config.inc.php';
if (file_exists($my_config)) {
require_once('my.config.inc.php');
} else {
require_once('config.inc.php');
}
require_once('db.php');
require_once('folders.php');
$filename = trim(basename($_GET['filename']));
if($pos = strpos($filename, '?')) {
$parts = explode('?', $filename);
$filename = array_shift($parts);
}
$filename_source = $config['folders']['images'] . DIRECTORY_SEPARATOR . $filename;
$filename_print = $config['folders']['print'] . DIRECTORY_SEPARATOR . $filename;
$filename_codes = $config['folders']['qrcodes'] . DIRECTORY_SEPARATOR . $filename;
$filename_thumb = $config['folders']['thumbs'] . DIRECTORY_SEPARATOR . $filename;
$status = false;
// text on print variables -start
$fontsize = $config['fontsize'];
$fontlocx = $config['locationx'];
$fontlocy = $config['locationy'];
$linespacing = $config['linespace'];
$fontrot = $config['rotation'];
$line1text = $config['textonprint']['line1'];
$line2text = $config['textonprint']['line2'];
$line3text = $config['textonprint']['line3'];
// text on print variables -end
// exit with error
if(!file_exists($filename_source)) {
echo json_encode(array('status' => sprintf('file "%s" not found', $filename_source)));
} else {
// print
// copy and merge
if(!file_exists($filename_print)) {
if($config['print_qrcode'] == true) {
// create qr code
if(!file_exists($filename_codes)) {
include('resources/lib/phpqrcode/qrlib.php');
$url = 'http://'.$_SERVER['HTTP_HOST'].'/download.php?image=';
QRcode::png($url.$filename, $filename_codes, QR_ECLEVEL_H, 10);
}
// merge source and code
list($width, $height) = getimagesize($filename_source);
$newwidth = $width + ($height / 2);
$newheight = $height;
$source = imagecreatefromjpeg($filename_source);
$code = imagecreatefrompng($filename_codes);
if($config['print_frame'] == true) {
$print = imagecreatefromjpeg($filename_source);
$rahmen = @imagecreatefrompng('resources/img/frames/frame.png');
$rahmen = ResizePngImage($rahmen, imagesx($print), imagesy($print));
$x = (imagesx($print)/2) - (imagesx($rahmen)/2);
$y = (imagesy($print)/2) - (imagesy($rahmen)/2);
imagecopy($print, $rahmen, $x, $y, 0, 0, imagesx($rahmen), imagesy($rahmen));
imagejpeg($print, $filename_print);
imagedestroy($print);
// $source needs to be redefined, picture with frame now exists inside $filename_print
imagedestroy($source);
$source = imagecreatefromjpeg($filename_print);
}
$print = imagecreatetruecolor($newwidth, $newheight);
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));
// text on image - start - IMPORTANT ensure you download Google Great Vibes font
if($config['is_textonprint'] == true) {
$fontcolour = imagecolorallocate($print, 0, 0, 0); // colour of font
imagettftext ($print, $fontsize, $fontrot, $fontlocx, $fontlocy, $fontcolour, 'resources/fonts/GreatVibes-Regular.ttf' , $line1text);
imagettftext ($print, $fontsize, $fontrot, $fontlocx, $fontlocy + $linespacing, $fontcolour, 'resources/fonts/GreatVibes-Regular.ttf' , $line2text);
imagettftext ($print, $fontsize, $fontrot, $fontlocx, $fontlocy + ($linespacing *2), $fontcolour, 'resources/fonts/GreatVibes-Regular.ttf' , $line3text);
}
//text on image - end
imagejpeg($print, $filename_print);
imagedestroy($code);
imagedestroy($source);
} else {
$print = imagecreatefromjpeg($filename_source);
if($config['print_frame'] == true) {
$rahmen = @imagecreatefrompng('resources/img/frames/frame.png');
$rahmen = ResizePngImage($rahmen, imagesx($print), imagesy($print));
$x = (imagesx($print)/2) - (imagesx($rahmen)/2);
$y = (imagesy($print)/2) - (imagesy($rahmen)/2);
imagecopy($print, $rahmen, $x, $y, 0, 0, imagesx($rahmen), imagesy($rahmen));
}
imagejpeg($print, $filename_print);
}
imagedestroy($print);
}
// print image
// fixme: move the command to the config.inc.php
$printimage = shell_exec(
sprintf(
$config['print']['cmd'],
$filename_print
)
);
echo json_encode(array('status' => 'ok', 'msg' => $printimage || ''));
}
function ResizePngImage($image, $max_width, $max_height)
{
$old_width = imagesx($image);
$old_height = imagesy($image);
$scale = min($max_width/$old_width, $max_height/$old_height);
$new_width = ceil($scale*$old_width);
$new_height = ceil($scale*$old_height);
$new = imagecreatetruecolor($new_width, $new_height);
imagealphablending( $new, false );
imagesavealpha( $new, true );
imagecopyresized($new, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
return $new;
}