-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimg.php
32 lines (28 loc) · 1.07 KB
/
img.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
// get imgage url, title, and width
$title = urlencode(urldecode($_GET["title"]));
$image_url = $_GET["imgurl"];
$width = $_GET["width"];
// get quality and filetype, or set defaults
$quality = intval($_GET["qual"]);
$filetype = $_GET["type"];
$quality = (0 < $quality && $quality <= 100) ? $quality : 70;
$filetype = ($filetype == 'jpg' || $filetype == 'png') ? $filetype : 'jpg';
// filename from unique hash
$path = "http://kijani.co/imagerenderer/svg.php?img={$image_url}&title={$title}&width={$width}";
$filename = 'cache/' . hash("md5", $path.$quality) . '.' . $filetype;
// create image from svg, if needed
$image = $filetype == 'jpg' ? @imagecreatefromjpeg($filename) : @imagecreatefrompng($filename);
if ( !$image ) {
`./phantomjs rasterize.js '{$path}' {$filename} {$quality}`;
$image = ($filetype == 'jpg') ? imagecreatefromjpeg($filename) : imagecreatefrompng($filename);
}
// output image
if ( $filetype == 'jpg' ) {
header("Content-type: image/jpeg");
imagejpeg($image);
} else {
header("Content-type: image/png");
imagepng($image);
}
?>