<?php
$max_width = 150; //Максимална широчина на thumb-овете
$max_height = 150; //Максимална височина на thumb-овете
$upfile = $_GET['image'];
$type = getimagesize($upfile);
Header("Content-type: ".$type['mime']."");
$size = getimagesize($upfile);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) )
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
ini_set('memory_limit', '1024M');
if($type['mime'] == "image/jpeg") {
$src = imagecreatefromjpeg($upfile);
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagejpeg($dst);
ImageDestroy($src);
ImageDestroy($dst);
}
elseif($type['mime'] == "image/png") {
$src = imagecreatefrompng($upfile);
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagepng($dst);
ImageDestroy($src);
ImageDestroy($dst);
}
elseif($type['mime'] == "image/gif") {
$src = imagecreatefromgif($upfile);
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagegif($dst);
ImageDestroy($src);
ImageDestroy($dst);
}
elseif($type['mime'] == "image/bmp") {
$src = imagecreatefrombmp($upfile);
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagebmp($dst);
ImageDestroy($src);
ImageDestroy($dst);
}
?>