<?php
//Высчитываем проценты
function procent_img($width, $info){
if($info[0] > ($width - 20)){
$prop = $info[0]/$info[1];
$W = $width - 20;
}elseif ($info[0] == ($width - 20)){
$W = $width - 20;
}else{
$prop = $info[1]/$info[0];
$W = $width - 20;
}
return $W; //Шлем ширину
}
// Это для широкоформатников
function wide_pictures($img, $src_image, $info){
$width = 620;
$height = 500;
$W = procent_img($width, $info);
$img = imagecreatetruecolor($width,$height)
or die(header("Location: index.php?error=1"));
$bac = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 611, 8, 8, 402, $bac);
imagecopyresampled($img, $src_image, 10, 10, 0, 0, 600, 390, $info[0], $info[1]);
$cnt = strlen($_POST['text']);
$gerek = $cnt * 4;
if(isset($_POST['text2']) && !empty($_POST['text2'])){
imagettftext($img, 20, 0, (($W/2) - $gerek), 430, $bac, "{$_SERVER['DOCUMENT_ROOT']}/ariblk.ttf", $_POST['text']);
imagettftext($img, 20, 0, (($W/2) - $gerek), 480, $bac, "{$_SERVER['DOCUMENT_ROOT']}/timesi.ttf", $_POST['text2']);
}else{
imagettftext($img, 20, 0, (($W/2) - $gerek), 460, $bac, "{$_SERVER['DOCUMENT_ROOT']}/ariblk.ttf", $_POST['text']);
}
return $img;
}
// Это для узкоформатников
function narrow_pictures($img, $src_image, $info){
$width = 320;
$height = 520;
$W = procent_img($width, $info);
$img = imagecreatetruecolor($width,$height)
or die(header("Location: index.php?error=1"));
$bac = imagecolorallocate($img, 255, 255, 255);
imagefilledrectangle($img, 310, 8, 8, 440, $bac);
imagecopyresampled($img, $src_image, 10, 10, 0, 0, 300, 430, $info[0], $info[1]);
$cnt = strlen($_POST['text']);
$gerek = $cnt * 4;
if(isset($_POST['text2']) && !empty($_POST['text2'])){
imagettftext($img, 20, 0, (($W/2) - $gerek), 470, $bac, "{$_SERVER['DOCUMENT_ROOT']}/ariblk.ttf", $_POST['text']);
imagettftext($img, 20, 0, (($W/2) - $gerek),500, $bac, "{$_SERVER['DOCUMENT_ROOT']}/timesi.ttf", $_POST['text2']);
}else{
imagettftext($img, 20, 0, (($W/2) - $gerek), 485, $bac, "{$_SERVER['DOCUMENT_ROOT']}/ariblk.ttf", $_POST['text']);
}
return $img;
}