<?php
#-----------------------------------------------------#
# ============ЗАГРУЗ-ЦЕНТР============= #
# 	 Автор : Sea #
# E-mail : x-sea-x@ya.ru #
# ICQ : 355152215 #
# Вы не имеете права распространять данный скрипт. #
# 		По всем вопросам пишите в ICQ. #
#-----------------------------------------------------#

// mod Gemorroj

require 'moduls/ini.php';
require 'moduls/connect.php';

header('Content-type: image/jpeg');
header('Cache-Control: public');
header('Pragma: cache');

$W = intval(@$_GET['W']);
$H = intval(@$_GET['H']);
$id = intval(@$_GET['id']);

$pic = urldecode(mysql_result(mysql_query('SELECT TRIM(`path`) FROM `files` WHERE `id` = '.$id.' LIMIT 1'), 0));

if (substr($pic, 0, 1) != '.') {

    switch (strtolower(pathinfo($pic, PATHINFO_EXTENSION))) {
    case 'gif':
        $old = imagecreatefromgif($pic);
        break;


    case 'jpg':
    case 'jpeg':
    case 'jpe':
        $old = imagecreatefromjpeg($pic);
        break;


    case 'png':
        $old = imagecreatefrompng($pic);
        break;


    default:
        exit('Bad format');
        break;
    }

    $wn = imagesx($old);
    $hn = imagesy($old);
    $prew = true;
    if (!$W || !$H) {
        $prew = false;
        $size = explode('*', $setup['prev_size']);
        $W = round(intval($size[0])); // ширина картинки
        $H = round(intval($size[1])); // высота картинки
    }

    $sxy = round($wn / $hn, 3);
    if ($sxy < 1) {
        $W = intval($H * $sxy);
    } else {
        $H = intval($W / $sxy);
    }

    $new = imagecreatetruecolor($W, $H);
    imagecopyresampled($new, $old, 0, 0, 0, 0, $W, $H, $wn, $hn);

    if ($setup['marker'] && $prew) {
        // фон
        $bg = imagecolorallocate($new, 255, 255, 255);
        // цвет
        $color = imagecolorallocate($new, 200, 200, 200);

        imagestring($new, 2, ($W / 2) - (strlen($setup['text_marker']) * 3), 1, $setup['text_marker'], $color);
    }

    imagejpeg($new, '', 75);
    if (!$prew) {
        mysql_query('UPDATE `files` SET `loads`=`loads`+1, `timeload`=' . $_SERVER['REQUEST_TIME'] . ' WHERE `id`=' . $id);
    }
}

?>