Jak za pomocą GD wyświetlić obrazek i dodać do niego tekst?

0

Mam tu coś takiego:
Ale nic mi się nie wyświetla! Chyba zaraz oszaleje!

<?php
//Set the Content Type
header('Content-type: image/jpeg');

// Create Image From Existing File
$jpg_image = imagecreatefromjpeg($_SERVER[DOCUMENT_ROOT]/images/26784.jpg);

// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 255, 255, 255);

// Set Path to Font File
$font_path = "$_SERVER[DOCUMENT_ROOT]/fonts/RobotoSlab-Regular.ttf";

// Set Text to Be Printed On Image
$text = "This is a sunset!";

// Print Text On Image
imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

// Send Image to Browser
imagejpeg($jpg_image);

// Clear Memory
imagedestroy($jpg_image);
?>

;-)

1
	$jpg_image = imagecreatefromjpeg('audi.jpg');
	$white = imagecolorallocate($jpg_image, 255, 255, 255);
	$font = 'C:\\arial.ttf';
	$text = "This is a sunset!";
	imagettftext($jpg_image, 15, 0, 75, 300, $white, $font, $text);
	header("Content-type: image/png");
	imagejpeg($jpg_image);
	imagedestroy($jpg_image);

Primo, @cerrato powiedz mu coś.
Duo, napisali Ci już w poprzednim temacie - sprawdź gdzie masz błędy:

<?php
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);

	$jpg_image = imagecreatefromjpeg("$_SERVER[DOCUMENT_ROOT]/images/26784.jpg");
	$white = imagecolorallocate($jpg_image, 255, 255, 255);
	$font_path = "$_SERVER[DOCUMENT_ROOT]/fonts/RobotoSlab-Regular.ttf";
	$text = "This is a sunset!";
	imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);
	imagejpeg($jpg_image);
	imagedestroy($jpg_image);
?>
0

Bardzo proszę. Oto co mi wyskakuje. Haha. Po egzekucji skryptu powyżej.
Może ktoś zna jakąś solucję?

title

0
<?php
// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(600, 600);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 600, 600, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = '/fonts/RobotoSlab-Regular.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
0

W końcu się udało!

title

<?php
// Set the content-type
header('Content-Type: image/jpeg');

/* Attempt to open */
$im = imagecreatefromjpeg("$_SERVER[DOCUMENT_ROOT]/images/26784.jpg");

// The text to draw
$text = 'Testing...';

// Replace path by your own font path
$font = '/fonts/RobotoSlab-Regular.ttf';

// Add some shadow to the text
// imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 50, 0, 10, 80, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagejpeg($im);
imagedestroy($im);
?>
1

Zastanawiam się nad jednym. Jaki ma sens rozmowa z samym sobą?

0

Taka, że teraz pomożesz mi zmienić rozmiar jpeg w GD php. Okey?

1 użytkowników online, w tym zalogowanych: 0, gości: 1