Вход Регистрация
Файл: spuff.ru/avatars/resize.php
Строк: 98
<?php
require_once '../includes/sys.php';

$config['previewsize'] = '128';
$dir = isset($_GET['dir']) ? check($_GET['dir']) : '';
$name = isset($_GET['name']) ? check($_GET['name']) : '';

if (
preg_match('|^[a-z0-9_-/]+$|i'$dir) && preg_match('|^[a-z0-9_.-]+$|i'$name)) {
    if (
file_exists('../'.$dir '/' $name)) {
        
$getim getimagesize('../'.$dir '/' $name);

        if (
$getim[2] == || $getim[2] == || $getim[2] == 3) {
            
$width $getim[0];
            
$height $getim[1];

            if (
$width $config['previewsize'] || $height $config['previewsize']) {
                
$x_ratio $config['previewsize'] / $width;
                
$y_ratio $config['previewsize'] / $height;

                if ((
$x_ratio $height) < $config['previewsize']) {
                    
$tn_height ceil($x_ratio $height);
                    
$tn_width $config['previewsize'];
                } else {
                    
$tn_width ceil($y_ratio $width);
                    
$tn_height $config['previewsize'];
                } 
                
// -------------------------------//
                
if ($getim[2] == 2) {
                    
$img imagecreatefromjpeg('../'.$dir '/' $name);
                    
$dst imagecreatetruecolor($tn_width$tn_height);
                    
imagecopyresampled($dst$img0000$tn_width$tn_height$width$height);

                    
header('content-type: image/jpeg');
                    
header('Content-Disposition: filename="' $name '"');
                    
imagejpeg ($dstnull75);
                    
imagedestroy($img);
                    
imagedestroy($dst);
                } 
                
// -------------------------------//
                
if ($getim[2] == 1) {
                    
$img imagecreatefromgif('../'.$dir '/' $name);
                    
$dst imagecreatetruecolor($tn_width$tn_height);

                    
$colorTransparent imagecolortransparent($img);
                    
imagepalettecopy($img$dst);
                    
imagefill($dst00$colorTransparent);
                    
imagecolortransparent($dst$colorTransparent);
                    
imagetruecolortopalette($dsttrue256);

                    
imagecopyresampled($dst$img0000$tn_width$tn_height$width$height);

                    
header('content-type: image/gif');
                    
header('Content-Disposition: filename="' $name '"');
                    
imagegif ($dst);
                    
imagedestroy($img);
                    
imagedestroy($dst);
                } 
                
// -------------------------------//
                
if ($getim[2] == 3) {
                    
$img imagecreatefrompng('../'.$dir '/' $name);
                    
$dst imagecreatetruecolor($tn_width$tn_height);

                    
$colorTransparent imagecolortransparent($img);
                    
imagepalettecopy($img$dst);
                    
imagefill($dst00$colorTransparent);
                    
imagecolortransparent($dst$colorTransparent);
                    
imagetruecolortopalette($dsttrue256);

                    
imagecopyresampled($dst$img0000$tn_width$tn_height$width$height);

                    
header('content-type: image/png');
                    
header('Content-Disposition: filename="' $name '"');
                    
imagepng ($dst);
                    
imagedestroy($img);
                    
imagedestroy($dst);
                } 
            } else {
                
$filename file_get_contents('../'.$dir '/' $name);
                
header('Content-type: ' $getim['mime']);
                
header('Content-Disposition: filename="' $name '"');
                
header('Content-Length: ' strlen($filename));
                echo 
$filename;
            } 
        }
    }

exit;

?>
Онлайн: 2
Реклама