Наложение текста на картинку

Статус
В этой теме нельзя размещать новые ответы.

AsanBosam

Постоялец
Регистрация
1 Мар 2009
Сообщения
139
Реакции
11
Доброе время суток!
Подскажите пожалуйста есть ли скрипт у которого можно указать через урл текст который будет накладываться на изображение, пример:
/img.php?text=nulled.ws
 
Посмотри тут

Целый класс для работы с изображениями.

Вот этим пользуюсь
PHP:
<?
function writeTextOnImage($filename, $text, $font_file)
{
if ($filename == "") {
exit();}
$size_img = getimagesize($filename);
if ($size_img[2]==2) $src_img = imagecreatefromjpeg($filename);
else if ($size_img[2]==1) $src_img = imagecreatefromgif($filename);
else if ($size_img[2]==3) $src_img = imagecreatefrompng($filename);
if (!$src_img) exit();
$height_font = $size_img[0]/100*5;
// Назначаем цвет
$color = imagecolorallocatealpha($src_img, 255,251, 0, 0);
$angle = 0;
// Запись текста поверх изображения
$tW=$size_img[0]/100*50;
$tH=$size_img[1]- $height_font -1;
$box = imagettftext($src_img, $height_font, $angle, $tW, $tH, $color, $font_file, $text);
// Назначаем цвет
$color = imagecolorallocatealpha($src_img, 255,0, 0, 0);
$angle = 0;
// Запись текста поверх изображения
$tW=$size_img[0]/100*50;
$tH=$size_img[1]- $height_font;
$box = imagettftext($src_img, $height_font, $angle, $tW, $tH, $color, $font_file, $text);
// Сохраняем результат
if ($size_img[2]==2)
{
#header ("Content-type: image/jpeg");
imagejpeg($src_img, $filename,100);
}
else if ($size_img[2]==1)
{
#header ("Content-type: image/gif");
imagegif($src_img, $filename,100);
}
else if ($size_img[2]==3)
{
#header ("Content-type: image/png");
imagepng($src_img, $filename,100);
}
imagedestroy($src_img);
return true;
}
Пример вызова
PHP:
<?php
ini_set("max_execution_time", "0");
ignore_user_abort(0);
include "function/function.php";
$abspath_folder = 'result';
if ($handle = opendir($abspath_folder)) {
		while (false !== ($file = readdir($handle))) {
			if ($file != '.' && $file != '..' && $file != 'CVS' && $file != 'index.html' ) {
				$type_file = explode('.', $file);
				if (is_file("$abspath_folder/$file") && ($type_file[1]=='jpg' or $type_file[1]=='gif' or $type_file[1]=='png'))
				writeTextOnImage("$abspath_folder/$file", '.: TXT :.', 'function/segmcr.ttf');
// Если тут поменять '.: TXT :.' на $_GET['text'] будет нужный вариант
			}
			$fl++;
		}
	}
	closedir($handle);
echo 'END '.$fl;
Скрипт переписывает все картинки в указанной папке!!!
Скрипт применялся для собственных целей :)
 
Используйте функцию imagettftext(), можно применять любые ttf-шрифты.
 
Код:
<?php
$img="images/bilet.jpg";
$pic = ImageCreateFromjpeg($img); //открываем рисунок в формате JPEG
Header("Content-type: image/jpeg"); //указываем на тип передаваемых данных
$color=ImageColorAllocate($pic, 250, 0, 0); //получаем идентификатор цвета
/* определяем место размещения текста по вертикали и горизонтали */
$h = 260; //высота
$w = 220; //ширина
/* выводим текст на изображение */
ImageTTFtext($pic, 26, 0, $w, $h, $color, "Times", "Simona");
ImageTTFtext($pic, 26, 0, $w-50, $h+65, $color, "Times", time());

Imagejpeg($pic,"images/".time().".jpg"); //сохраняем рисунок в формате JPEG
ImageDestroy($pic); //освобождаем память и закрываем изображение
?>
 
Статус
В этой теме нельзя размещать новые ответы.
Назад
Сверху