Файл: setk/make_demotivate.php
Строк: 119
<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';
only_reg();
$set['title']='Создать демотиватор';
include_once 'sys/inc/thead.php';
title();
function copyright($img)
{
global $set;
if ($copy=@imagecreatefromstring(file_get_contents(H.'cop.png')))
{
$img_x=imagesx($img);
$img_y=imagesy($img);
$copy_x=imagesx($copy);
$copy_y=imagesy($copy);
$w=intval(min($img_x/2.5,$copy_x,128));
$h=intval(min($img_y/2.5,$copy_y,64));
$x_ratio = $w/$copy_x;
$y_ratio = $h/$copy_y;
if (($copy_x <= $w) && ($img_y <= $h))
{
$dstW = $copy_x;
$dstH = $copy_y;
}
elseif (($x_ratio * $copy_y) < $h)
{
$dstH = ceil($x_ratio * $copy_y);
$dstW = $w;
}
else
{
$dstW = ceil($y_ratio * $copy_x);
$dstH = $h;
}
imagecopyresampled($img, $copy, $img_x-$dstW, $img_y-$dstH, 0, 0, $dstW, $dstH, $copy_x, $copy_y);
}
return $img;
}
if (isset($_FILES['file']))
{
if (preg_match('#.jpe?g$#i',$_FILES['file']['name']) && $imgc=@imagecreatefromjpeg($_FILES['file']['tmp_name']))
{
$img_x=imagesx($imgc);
$img_y=imagesy($imgc);
if($_POST['t1']==NULL && $_POST['t2']==NULL)exit('Не указан текст');
$cool=$img_y*0.03;
if(isset($_POST['t1']) && $_POST['t1']!=NULL)$cool=$cool+$img_y*0.09;
if(isset($_POST['t2']) && $_POST['t2']!=NULL)$cool=$cool+$img_y*0.09;
$screen=imagecreatetruecolor($img_x*1.08, $img_y*1.08+$cool);
$white = imagecolorallocate($screen, 255, 255, 255);
imagefilledrectangle($screen, $img_x*0.03, $img_y*0.03, $img_x*1.05, $img_y*1.05, $white);
imagecopyresampled($screen, $imgc, $img_x*0.04, $img_y*0.04, 0, 0, $img_x, $img_y, $img_x, $img_y);
if($_POST['t1']!=NULL){
$ceil_top = ceil(($img_x+$img_y)/47); //// Размер верхней строки
$text = $_POST['t1'];
$font = 'sys/fonts/tahoma.ttf';
$bbox = imageftbbox($ceil_top , 0, $font, $text);
$x = (imagesx($screen) - $bbox[4])/2;
imagefttext($screen, $ceil_top, 0, $x, $img_y*1.13, $white, $font, bbcode($text));
}
if($_POST['t2']!=NULL){
$ceil_bottom = ceil(($img_x+$img_y)/52);//// Размер нижней строки
$text = $_POST['t2'];
$font = 'sys/fonts/tahoma.ttf';
$bbox = imageftbbox($ceil_bottom, 0, $font, $text);
$x = (imagesx($screen) - $bbox[4])/2;
imagefttext($screen, $ceil_bottom, 0, $x, $img_y*1.21, $white, $font, $text);
}
imagedestroy($imgc);
$y=imagesy($screen);
imagefttext($screen, 11, 0, 5, $y-5, $white, $font, $_SERVER['HTTP_HOST']);
$screen=copyright($screen);
$n=time();
imagejpeg($screen,H."dem/$n.jpg",100);
@chmod(H."dem/$n.jpg",0777);
imagedestroy($screen);
msg("Демотиватор создан");
echo "<div class='p_m'><img src='dem/$n.jpg' width='200'><a href='dem/$n.jpg'><br />Скачать оригинал!</a></div>";
echo "<a href='?'>Назад</a>";
include_once 'sys/inc/tfoot.php';
exit;
}
}
err();
aut();
if(isset($_GET['del']) && $_GET['del']!=NULL && $user['level']>0)unlink('dem/'.$_GET['del']);
$opendir=opendir(H.'dem');
while ($f=readdir($opendir)){
if($f=='.' || $f=='..' || $f=='.htaccess')continue;
$file[]=$f;
}
if(isset($file))$k_post=count($file);else$k_post=0;
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$count=$set['p_str']*$page-$set['p_str'];
echo "<form method='post' enctype='multipart/form-data' action='?$passgen'>n";
echo "<table class='post'>n";
echo " <td colspan='2'>n";
echo "<input type='file' name='file' accept='image/*,image/gif,image/png,image/jpeg' /><br />n";
echo "<input name='t1' /><br />n";
echo "<input name='t2' /><br />n";
echo "<input value='Создать' type='submit' />n";
echo "</table>n";
echo "</form>n";
if(isset($file))
rsort($file);
if($k_post==0)echo "Еще не созданы демотиваторы, будь первым";
for($c=$count;isset($file[$c]);$c++){
if($count+$set['p_str']<=$c)break;
if($file[$c]=='.' || $file[$c]=='..' || $file[$c]=='.htaccess')continue;
if($c%2==1)echo "<div class='p_t'>";
echo "<a href='dem/$file[$c]'><img src='dem/$file[$c]' width='200'></a><br />";
if($user['level']>0)echo "<a href='?page=$page&del=$file[$c]'>[d e l e t e]</a>";
echo " </td>n";
}
if ($k_page>1)str("?",$k_page,$page);
include_once 'sys/inc/tfoot.php';
?>