Файл: load_image.php
Строк: 99
<?php
/**
* @author [FaNiska]
* @copyright 2009
* Загруз центр
* Предложения, идеи, вопросы и об ошибках писать в icq 65-64-538 или на mobi-m-ru@ya.ru
*/
session_start();
include 'inc/db_connect.php';
include 'inc/function.php';
include 'inc/set.php';
header('Content-type: image/jpeg');
$W = valid_int($_GET['W']);
$H = valid_int($_GET['H']);
if (isset($_GET['id']) && isset($_GET['c']))
{
$id = valid_int($_GET['id']);
$table = clean($_GET['c']);
} else
{
header("location: index.php?error=invalid_id");
exit();
}
$file_info = mysql_fetch_row(mysql_query('SELECT TRIM(`s_name`) FROM `' . $table . '` WHERE `id` = ' . $id . ' LIMIT 1'));
$pic = urldecode(htmlspecialchars($file_info[0]));
if (substr($pic, 0, 1) != '.')
{
if (preg_match('/.gif$/i', $pic))
{
$old = imageCreateFromGif($pic);
$ras = 'gif';
} elseif (preg_match('/.jpg$|.jpeg$|.jpe$/i', $pic))
{
$old = imageCreateFromJpeg($pic);
$ras = 'jpg';
} elseif (preg_match('/.png$/i', $pic))
{
$old = imageCreateFromPNG($pic);
$ras = 'png';
}
{
$wn = imageSX($old);
$hn = imageSY($old);
$prew = 1;
if (!$W and !$H)
{
$prew = 0;
$size = explode('*', $setup['prev_size']);
$W = round(valid_int($size[0])); // ширина картинки
$H = round(valid_int($size[1])); // высота картинки
}
$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 = $table . '_' . $id . '_' . $setup['mark_text'];
if ($ras == 'jpg')
{
header("Content-type: image/jpeg");
header("Content-Disposition: attachment; filename=$name.jpg");
ImageJpeg($old, 'temp/' . $table . $id, 100);
header("Accept-Ranges: bytes");
header("Content-length: " . filesize('temp/' . $table . $id) . "");
unlink('temp/' . $table . $id);
ImageJpeg($old, null, 100);
} elseif ($ras == 'gif')
{
header("Content-type: image/gif");
header("Content-Disposition: attachment; filename=$name.gif");
Imagegif($old, 'temp/' . $table . $id, 100);
header("Accept-Ranges: bytes");
header("Content-length: " . filesize('temp/' . $table . $id) . "");
unlink('temp/' . $table . $id);
ImageGif($old);
} elseif ($ras == 'png')
{
//imagecolortransparent($screen,0);
header("Content-type: image/png");
header("Content-Disposition: attachment; filename=$name.png");
Imagepng($old, 'temp/' . $table . $id, 100);
header("Accept-Ranges: bytes");
header("Content-length: " . filesize('temp/' . $table . $id) . "");
unlink('temp/' . $table . $id);
ImagePng($old);
}
imagedestroy($old);
mysql_query('UPDATE `' . $table . '` SET `count`=`count`+1, `lastload`=' . time() . ' WHERE `id`=' . $id);
exit;
}
}
?>