forked from dionyziz/Life
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thumb.php
27 lines (27 loc) · 815 Bytes
/
thumb.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
<?php
if ( !isset( $_GET[ 'file' ] ) ) {
die( 'File not specified' );
}
$file = basename( $_GET[ 'file' ] );
$filename = 'uploads/' . $file;
$im = @imagecreatefromstring( file_get_contents( $filename ) );
if ( $im !== false ) {
$w = imagesx( $im );
$h = imagesy( $im );
$maxw = 500;
$ratio = 1;
if ( $w > $maxw ) {
$ratio = $maxw / $w;
}
$neww = $ratio * $w;
$newh = $ratio * $h;
$thumb = imagecreatetruecolor( $neww, $newh );
imagecopyresampled( $thumb, $im, 0, 0, 0, 0, $neww, $newh, $w, $h );
header( 'Content-type: image/png' );
imagepng( $thumb );
}
else {
header( 'Content-type: image/jpg' ); // TODO account for png
file( $filename );
}
?>