-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremoteimage.php
More file actions
executable file
·58 lines (50 loc) · 1.25 KB
/
remoteimage.php
File metadata and controls
executable file
·58 lines (50 loc) · 1.25 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
<?php
include 'Database.php';
function makeDirIfNeeded($path) {
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
}
if (!isset($_GET['org'])) {
exit ('No org id');
}
$org_id = $_GET['org'];
$width = 100;
//Default value
if (isset($_GET['width'])) {
$width = intval($_GET['width']);
}
if (!isset($width) || $width <= 0) {
$width = 100;
exit("INVALID WIDTH");
//Default value just in case
}
$con = Database::getDefaultDBConnection();
// First see if the file is available locally. If not, then download and revise.
makeDirIfNeeded('./remoteimages/');
makeDirIfNeeded('./remoteimages/originals/');
makeDirIfNeeded('./remoteimages/snapshot/');
$query = "SELECT logo_url FROM orgs WHERE id=?";
$stmt = $con->prepare($query);
$stmt->bind_param("i", $org_id);
$stmt->execute();
$stmt->bind_result($logo_url);
if (!$stmt->fetch()) {
exit ("Invalid org");
}
if (!isset($logo_url)) {
exit ("Invalid url");
}
$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);
$img->thumbnailImage($width, 0);
header('Content-type: image/' . $img->getImageFormat());
echo $img;
$con->close();
?>