<?php
#-----------------------------------------------------#
# Зц Sea mod Ganjara                                  #
# 	 Автор : Slayer  with   Ganjar                    #
#    ICQ :   566003         993770                    #
#    Вы не имеете права распространять данный скрипт. #
# 		По всем вопросам пишите в ICQ.                  #
#-----------------------------------------------------#

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

header('Content-type: image/jpeg');
$setting = mysql_query('SELECT * FROM `zc_setting`;');

while($set = mysql_fetch_assoc($setting)){
$setup[$set['name']] = $set['value'];
}
$W = intval($_GET['W']);
$H = intval($_GET['H']);
$id = intval($_GET['id']);
$bab = intval($_GET['bab']);

$file_info = mysql_fetch_row(mysql_query('SELECT TRIM(`path`) FROM `'.$setup['pref'].'files` WHERE `id` = '.$id.' LIMIT 1'));

if($bab==1 OR !$bab){
$pic = urldecode(htmlspecialchars($file_info[0]));

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

if(preg_match('/\.gif$/i', $pic)){$old = imageCreateFromGif($pic);}
elseif(preg_match('/\.jpg$|\.jpeg$|\.jpe$/i', $pic)){$old = imageCreateFromJpeg($pic);}
elseif(preg_match('/\.png$/i', $pic)){$old = imageCreateFromPNG($pic);}
{
$wn = imageSX($old);
$hn = imageSY($old);
$prew = 1;
if(!$W and !$H)
{
$prew = 0;
$size = explode('*',$setup['prev_size']);
$W = round(intval($size[0])); // ширина картинки
$H = round(intval($size[1])); // высота картинки
}
$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,null,100);
if(!$bab)
{
mysql_query('UPDATE `'.$setup['pref'].'files` SET `loads`=`loads`+1, `timeload`='.$time.' WHERE `id`='.$id);
}
}
}}
elseif($bab==2)
 {
 $filename = pathinfo($file_info[0]);
 $filename2 = str_replace('.'.$filename['extension'],'',$filename['basename']); 
 $filename = $filename['basename'];
 
 if($_GET['open']==1)  $filename=$file_info[0].'.gif';
 elseif(is_file($setup['spath'].'/'.$filename.'.gif'))      $filename=$setup['spath'].'/'.$filename.'.gif';
 elseif(is_file($setup['spath'].'/'.$filename.'.jpg'))  $filename=$setup['spath'].'/'.$filename.'.jpg';
 elseif(is_file($setup['spath'].'/'.$filename.'.jpe'))  $filename=$setup['spath'].'/'.$filename.'.jpe';
 elseif(is_file($setup['spath'].'/'.$filename.'.jpeg')) $filename=$setup['spath'].'/'.$filename.'.jpeg';
 elseif(is_file($setup['spath'].'/'.$filename.'.png'))  $filename=$setup['spath'].'/'.$filename.'.png';  
 elseif(is_file($setup['spath'].'/'.$filename2.'.gif'))  $filename=$setup['spath'].'/'.$filename2.'.gif';
 
  $pic = urldecode(htmlspecialchars($filename));

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

if(preg_match('/\.gif$/i', $pic)){$old = imageCreateFromGif($pic);}
elseif(preg_match('/\.jpg$|\.jpeg$|\.jpe$/i', $pic)){$old = imageCreateFromJpeg($pic);}
elseif(preg_match('/\.png$/i', $pic)){$old = imageCreateFromPNG($pic);}
{
$wn = imageSX($old);
$hn = imageSY($old);
$prew = 1;
if(!$W and !$H)
{
$prew = 0;
$size = explode('*',$setup['prev_size']);
$W = round(intval($size[0])); // ширина картинки
$H = round(intval($size[1])); // высота картинки
}
$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,null,100);

}
}}
?>