-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocalimage.php
executable file
·55 lines (49 loc) · 1.19 KB
/
localimage.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
<?php
namespace greenbase;
include_once 'get_config.php';
function makeDirIfNeeded($path) {
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
}
if (!isset($_GET['org_id'])) {
exit ('No org id');
}
//TODO: If the image fails to load, set logo_details valid = 0;
$org_id = $_GET['org_id'];
$width = 0;
$height = 0;
if (isset($_GET['width'])) {
$width = intval($_GET['width']);
}
if (isset($_GET['height'])) {
$height = intval($_GET['height']);
}
if ($width == 0 && $height == 0) {
//use default value for width only
$width = 100;
}
$logo_url = './remoteimages/originals/logo_' . $org_id . '.png';
if (!file_exists($logo_url)) {
$logo_url = './img/no_logo.png';
if (!file_exists($logo_url)) {
echo (getcwd());
exit ("Invalid file.");
}
}
$handle = fopen($logo_url, 'rb');
$img = new \Imagick();
//exit ( "version" . $img->getVersion()['versionString']);
$img->readImageFile($handle);
if (!$img->trimImage(0.4)) {
exit ("Trim failed");
}
$img->setImagePage(0, 0, 0, 0);
if ($width > 0 && $height > 0) {
$img->thumbnailImage($width, $height, true);
} else {
$img->thumbnailImage($width, $height, false);
}
header('Content-type: image/' . $img->getImageFormat());
echo $img;
?>