Просмотр файла resize_img.php

Размер файла: 2.34Kb
<?php
require('require/configuration.php');
if (!isset($_GET['img']))
{
exit;
}
#################
#################
$image='datapic/'.$_GET['img'];
if(!file_exists($image)){
exit;
}
$ext=strtolower(substr($_GET['img'],strrpos($_GET['img'],'.')+1));
if($ext=='jpg'){
$ext='jpeg';
}
switch($ext)
{
case('jpeg'):
$size=getimagesize($image); 
$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; 
} 

$src=imagecreatefromjpeg($image); 
$dst=imagecreatetruecolor($tn_width,$tn_height); 
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height); 
header('Content-type: image/jpeg'); 
imagejpeg($dst, null, 100); 
imagedestroy($src); 
imagedestroy($dst);
break;
#################
#################
case('gif'):
$size=getimagesize($image); 
$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; 
}
$src=imagecreatefromgif($image); 
$dst=imagecreatetruecolor($tn_width,$tn_height); 
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height); 
header('Content-type: image/gif'); 
imagegif($dst);
imagedestroy($src); 
imagedestroy($dst);
break;
#################
#################
case('png'):
$size=getimagesize($image); 
$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;
}
$src=imagecreatefrompng($image);
$dst=imagecreatetruecolor($tn_width,$tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height);
imagecolortransparent($dst, '0');
header('Content-type: image/png');
imagepng($dst);
imagedestroy($src); 
imagedestroy($dst);
break;
}
?>