-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicon.php
55 lines (45 loc) · 1.88 KB
/
icon.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
include_once 'data.php';
include_once 'functions.php';
session_write_close();
// Files
$file = preg_replace('/^0-9\.pdf/', '', $_GET['file']);
$png = 'library/pngs/' . $file . '.1.png';
$icon = $temp_dir . DIRECTORY_SEPARATOR . 'i-librarian' . DIRECTORY_SEPARATOR . $file . '.1.icon.png';
// Paths
$pdf_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library';
$png_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'pngs';
// Content type
header('Content-Type: image/png');
// Output from cache
if (is_readable($icon) &&
filemtime($pdf_path . DIRECTORY_SEPARATOR . $file) < filemtime($icon)) {
echo file_get_contents($icon);
die();
}
// Make PNG if not found
if (!is_readable($png) ||
filemtime($png_path . DIRECTORY_SEPARATOR . $file . '.1.png') < filemtime($pdf_path . DIRECTORY_SEPARATOR . $file)) {
exec(select_ghostscript() . " -dSAFER -sDEVICE=png16m -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dDOINTERPOLATE -dFirstPage=1 -dLastPage=1 -o \"" . $png_path . DIRECTORY_SEPARATOR . $file . ".1.png\" \"" . $pdf_path . DIRECTORY_SEPARATOR . $file . "\"");
}
if (!is_readable($png)) {
// Error! Ghostscript DOES NOT WORK
$image_p = @imagecreate(360, 240);
$background_color = imagecolorallocate($image_p, 255, 255, 255);
$text_color = imagecolorallocate($image_p, 255, 0, 0);
imagestring($image_p, 3, 20, 20, "Error! Program Ghostscript not functional.", $text_color);
} else {
// Icon dimensions
$new_width = 360;
$new_height = 240;
// Resample
list($width, $height) = getimagesize($png);
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($png);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $width / 1.5);
}
// Output
imagepng($image_p, $icon, 1);
imagepng($image_p, null, 1);
imagedestroy($image_p);
?>