-
Notifications
You must be signed in to change notification settings - Fork 273
/
preview.php
32 lines (27 loc) · 964 Bytes
/
preview.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
<?php
require_once("sandphoto.inc");
$filename = "/var/www/sandcomp/apache/htdocs/sandphoto/sample.jpg";
$temp_path = "/var/www/sandcomp/apache/htdocs/sandphoto/temp";
$target_type = $_GET["t"];
$container_type = $_GET["c"];
$bgcolorid= $_GET["b"];
$cacheFilename = "preview-" . $target_type . "-" . $container_type ."-".$bgcolorid . ".png";
$cachePath = $temp_path . "/" . $cacheFilename;
if (!file_exists($cachePath))
{
$parser = new PhotoTypeParser();
$parser->parse('phototype.txt');
$cw = $parser->get_width($container_type);
$ch = $parser->get_height($container_type);
$tw = $parser->get_width($target_type);
$th = $parser->get_height($target_type);
$p = new Photo();
$p->set_container_size($cw, $ch);
$p->set_target_size($tw, $th);
$n = $p->put_photo($filename, $bgcolorid);
$p->preview_image($cachePath);
system("/usr/bin/optipng " . $cachePath . " >/dev/null 2>/dev/null");
}
header("location: temp/" . $cacheFilename);
exit();
?>