forked from andreknieriem/photobooth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.php
62 lines (52 loc) · 2.11 KB
/
print.php
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
<?php
require_once('config.inc.php');
require_once('db.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;
// exit with error
if(!file_exists($filename_source)) {
echo json_encode(array('status' => sprintf('file "%s" not found', $filename_source)));
}
// print
if(file_exists($filename_source)) {
// copy and merge
if(!file_exists($filename_print)) {
// 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);
$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));
imagejpeg($print, $filename_print);
imagedestroy($print);
imagedestroy($code);
imagedestroy($source);
}
// 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 || ''));
}