Вход Регистрация
Файл: thumb.php
Строк: 54
<?php
include 'system/mysql.php';
include 
'system/sys_func.php';

if (!empty(
$_GET['src'])) {
    
$src = filter($_GET['src']);
    
$name = strtolower($src);
    if (
preg_match('#.jpe?g$#i', $name)) $f = 'jpg';
    elseif (
preg_match('#.png$#i', $name)) $f = 'png';
    elseif (
preg_match('#.gif$#i', $name)) $f = 'gif';
}
if (
$_GET['t'] != 'a' && $_GET['t'] != 'b') {
    exit(
'Неправильный параметр.');
}
$size = getimagesize('files/'. $src);

if (
$f == 'jpg') $img = imagecreatefromjpeg('files/'. $src);
elseif (
$f == 'png') $img = imagecreatefrompng('files/'. $src);
elseif (
$f == 'gif') $img = imagecreatefromgif('files/'. $src);
$w_src = imagesx($img);
$h_src = imagesy($img);

if (
$_GET['t'] == 'a') {
    
$width = 200;
    
$height = 200;
    
$ratio = $w_src/$width;
    
$ratio2 = $h_src/$height;
    if (
$ratio > $ratio2) {
        
$w_dest = round($w_src/$ratio);
        
$h_dest = round($h_src/$ratio);
    } elseif (
$ratio < $ratio2) {
        
$w_dest = round($w_src/$ratio2);
        
$h_dest = round($h_src/$ratio2);
    }
    
$image = imagecreatetruecolor($w_dest, $h_dest);
    if (
$f == 'png') imagealphablending($image, false);
    if (
$f == 'gif') {
        
$tsi = imagecolortransparent($img);
        if (
$tsi >= 0 && $tsi < 255) {
            
$tc = imagecolorsforindex($img, $tsi);
            
$tdi = imagecolorallocate($image, $tc['red'], $tc['green'], $tc['blue']);
            
imagefill($image, 0, 0, $tdi);
            
imagecolortransparent($image, $tdi);
        }
    }
    
imagecopyresampled($image, $img, 0, 0, 0, 0, $w_dest, $h_dest, $w_src, $h_src);
    if (
$f == 'png') imagesavealpha($image, true);
    
header('Content-type: image/'. $f);
    if (
$f == 'jpg') imagejpeg($image, '', '100');
    elseif (
$f == 'png') imagepng($image);
    elseif (
$f == 'gif') imagegif($image, '', '100');
    
imagedestroy($image);
    
imagedestroy($img);
}

if (
$_GET['t'] == 'b') {
    
$width = 32;
    
$ratio = $w_src/$width;
    
$w_dest = round($w_src/$ratio);
    
$h_dest = round($h_src/$ratio);
    
$image = imagecreatetruecolor($w_dest, $w_dest);
    if (
$f == 'png') imagealphablending($image, false);
    if (
$f == 'gif') {
        
$tsi = imagecolortransparent($img);
        if (
$tsi >= 0 && $tsi < 255) {
            
$tc = imagecolorsforindex($img, $tsi);
            
$tdi = imagecolorallocate($image, $tc['red'], $tc['green'], $tc['blue']);
            
imagefill($image, 0, 0, $tdi);
            
imagecolortransparent($image, $tdi);
        }
    }
    if (
$w_src > $h_src) imagecopyresampled($image, $img, 0, 0, round((max($w_src, $h_src) - min($w_src, $h_src))/2), 0, $width, $width, min($w_src, $h_src), min($w_src, $h_src));
    elseif (
$w_src < $h_src) imagecopyresampled($image, $img, 0, 0, 0, round((max($w_src, $h_src) - min($w_src, $h_src))/2), $width, $width, min($w_src, $h_src), min($w_src, $h_src));
    elseif (
$w_src == $h_src) imagecopyresampled($image, $img, 0, 0, 0, 0, $width, $width, $w_src, $w_src);
    if (
$f == 'png') imagesavealpha($image, true);
    
header('Content-type: image/'. $f);
    if (
$f == 'jpg') imagejpeg($image, '', '100');
    elseif (
$f == 'png') imagepng($image);
    elseif (
$f == 'gif') imagegif($image, '', '100');
    
imagedestroy($image);
    
imagedestroy($img);
}
?>
Онлайн: 2
Реклама