root / docs / www / colonyscout / internal / get-thumb.php @ f59acf11
History | View | Annotate | Download (1.75 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
function exif_imagetype ( $filename ) { |
4 |
if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) { |
5 |
return $type; |
6 |
} |
7 |
return false; |
8 |
} |
9 |
|
10 |
//*-----Get new image size-----*//
|
11 |
if (isset($_GET["h"])) { |
12 |
$nHeight = $_GET["h"]; |
13 |
} else {
|
14 |
$nHeight = 75; |
15 |
} |
16 |
|
17 |
if (isset($_GET["w"])) { |
18 |
$nWidth = $_GET["w"]; |
19 |
} else {
|
20 |
$nWidth = 110; |
21 |
} |
22 |
|
23 |
|
24 |
//*-----Get source/destination directories-----*//
|
25 |
$cat = $_GET["cat"]; |
26 |
|
27 |
if ($cat == 'news') { |
28 |
$src_dir = 'news/img/'; |
29 |
$save_dir = 'news/img/thumbs/'; |
30 |
|
31 |
} else if ($cat == 'robo') { |
32 |
$src_dir = 'robotics/robo-img/'; |
33 |
$save_dir = 'robotics/thumbs/'; |
34 |
} |
35 |
|
36 |
|
37 |
|
38 |
//*-----Get filetype-----*//
|
39 |
$file_type = exif_imagetype($src_dir.$_GET["f"]); |
40 |
|
41 |
if ($file_type == IMAGETYPE_JPEG) { |
42 |
$src = imagecreatefromjpeg($src_dir.$_GET["f"]); |
43 |
} else if ($file_type == IMAGETYPE_PNG) { |
44 |
$src = imagecreatefrompng($src_dir.$_GET["f"]); |
45 |
} |
46 |
|
47 |
|
48 |
|
49 |
//*-----Resize before thumbnail-----*//
|
50 |
if (isset($_GET["resize"]) ) { |
51 |
// Capture the original size of the uploaded image
|
52 |
$width=imagesx($src); |
53 |
$height=imagesy($src); |
54 |
|
55 |
$newwidth=$nWidth; |
56 |
$newheight=($height/$width)*$newwidth; |
57 |
|
58 |
$tmp=imagecreatetruecolor($newwidth,$newheight); |
59 |
|
60 |
// this line actually does the image resizing
|
61 |
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); |
62 |
$src = $tmp; |
63 |
} |
64 |
|
65 |
|
66 |
// Create destination image
|
67 |
$dest = imagecreatetruecolor($nWidth, $nHeight); |
68 |
|
69 |
//Find center
|
70 |
$x = (imagesx($src)-$nWidth)/2; |
71 |
$y = (imagesy($src)-$nHeight)/2; |
72 |
|
73 |
// Copy
|
74 |
imagecopy($dest, $src, 0, 0, $x, $y, $nWidth, $nHeight); |
75 |
|
76 |
// Output and free from memory
|
77 |
header('Content-Type: image/jpg'); |
78 |
imagejpeg($dest,'',85); |
79 |
|
80 |
$success = imagejpeg($dest, $save_dir.$_GET["f"], 85); |
81 |
|
82 |
if ($success == true) { |
83 |
imagedestroy($dest);
|
84 |
imagedestroy($src);
|
85 |
}else {
|
86 |
echo "Error: File was not saved"; |
87 |
} |
88 |
|
89 |
?>
|