Файл: image.php
Строк: 89
<?php
/**
 * @author [FaNiska]
 * @copyright 2009
 * Загруз центр
 * Предложения, идеи, вопросы и об ошибках писать в icq 65-64-538 или на mobi-m-ru@ya.ru
 */
include 'inc/db_connect.php';
$setting = mysql_query('SELECT * FROM `setting`;');
while ($set = mysql_fetch_assoc($setting))
{
    $setup[$set['key']] = $set['value'];
}
if (isset($_GET['W']) && isset($_GET['H']))
{
    $W = intval($_GET['W']);
    $H = intval($_GET['H']);
} else
{
    $W = $setup['prev_w'];
    $H = $setup['prev_h'];
}
if (!isset($_GET['id']) || !isset($_GET['c']))
{
    exit();
}
$table = mysql_escape_string(htmlspecialchars($_GET['c']));
$id = intval($_GET['id']);
$file_info = mysql_fetch_array(mysql_query('SELECT `s_name` FROM `' . $table . '` WHERE `id` = ' . $id . ' LIMIT 1'));
if (file_exists($file_info['s_name']))
{
    $pathinfo = pathinfo($file_info['s_name']);
    $ras = $pathinfo['extension'];
    if ($ras == 'jpg' || $ras == 'jpeg')
    {
        $old = imageCreateFromJpeg($file_info['s_name']);
    } elseif ($ras == 'gif')
    {
        $old = imageCreateFromGif($file_info['s_name']);
    } elseif ($ras == 'png')
    {
        $old = imageCreateFromPNG($file_info['s_name']);
    }
    $wn = imageSX($old);
    $hn = imageSY($old);
    $new = imageCreateTrueColor($W, $H);
    imageCopyResampled($new, $old, 0, 0, 0, 0, $W, $H, $wn, $hn);
    if ($setup['mark_set'] == 1 && $setup['mark_text'] != null)
    {
        if ($setup['mark_size'] != null && $setup['mark_size'] != 0)
        {
            $setup['mark_size'] = intval($setup['mark_size']);
        } else
        {
            $setup['mark_size'] = 2;
        }
        // фон
        $bg = imagecolorallocate($new, 255, 255, 255);
        // цвет
        $color = imagecolorallocate($new, 100, 200, 0);
        imagestring($new, $setup['mark_size'], (strlen($setup['mark_text'])), ($H - 15), $setup['mark_text'], $color);
    }
    $name = $_SERVER['SERVER_NAME'] . '_' . $table . '_' . $id . '.' . $ras;
    if (isset($_GET['act']) && $_GET['act'] == 'd')
    {
        if ($ras == 'jpg' || $ras == 'jpeg')
        {
            ImageJpeg($new, 'temp/' . $name, 100);
            header('Location: temp/' . $name);
        } elseif ($ras == 'gif')
        {
            Imagegif($new, 'temp/' . $name, 100);
            header('Location: temp/' . $name);
        } elseif ($ras == 'png')
        {
            Imagepng($new, 'temp/' . $name, 100);
            header('Location: temp/' . $name);
        }
        imagedestroy($new);
        exit();
    } else
    {
        if ($ras == 'jpg' || $ras == 'jpeg')
        {
            header("Content-type: image/jpeg");
            ImageJpeg($new, null, 100);
        } elseif ($ras == 'gif')
        {
            header("Content-type: image/gif");
            ImageGif($new);
        } elseif ($ras == 'png')
        {
            header("Content-type: image/png");
            ImagePng($new);
        }
        imagedestroy($new);
        exit();
    }
} else
{
    $pic = 'inc/no.png';
    $old = imageCreateFromPNG($pic);
    $wn = imageSX($old);
    $hn = imageSY($old);
    $new = imageCreateTrueColor($W, $H);
    imageCopyResampled($new, $old, 0, 0, 0, 0, $W, $H, $wn, $hn);
    header("Content-type: image/png");
    ImagePng($new);
    imagedestroy($new);
    exit();
}
?>