So I'm trying to use the GD Library into my Wordpress website.
I've created the images.php page with this code :
function loadImage($name, $lastname) {
header ("Content-type: image/jpg");
$fond = imagecreatefromjpeg('link');
$font = "arial.ttf";
$noir = imagecolorallocate($fond, 0, 0, 0);
$blanc = imagecolorallocate($fond, 255, 255, 255);
imagettftext($fond, 20, 0, 600, 80, $blanc, $font, $name);
imagestring($fond, 5, 200, 200, $lastname, $blanc);
imagejpeg($fond, 'folder');
}
Then I execute loadImage("bob"); into another page. The imagestring function works, but not the imagettftexte. I tried everything but it seems that imagettftext doesnt work when giving args for the string to display.
If you guys could help me on that...
Thanks
I think you have done all but just need to change color something like:
$fond = imagecreatefromjpeg('link_of_image');
$font = "arial.ttf";
$noir = imagecolorallocate($fond, 0, 0, 0);
$blanc = imagecolorallocate($fond, 0, 0, 0);
imagettftext($fond, 20, 0, 600, 80, $blanc, $font, $name);
imagestring($fond, 5, 200, 200, $lastname, $blanc);
header ("Content-type: image/jpg");
imagejpeg($fond);
imagedestroy($fond);
Due to white color it not display.
I have edited your code and now it's run, only minor change in parameter of imagettftext.
imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
<?php
$name='anand';
$lastname='jain';
$fond = imagecreatefromjpeg('https://upload.wikimedia.org/wikipedia/en/9/94/Salisbury_mascotlogo.jpg');
$font = "arial.ttf";
$noir = imagecolorallocate($fond, 0, 0, 0);
$blanc = imagecolorallocate($fond, 0, 0, 0);
imagestring($fond, 5, 200, 200, $lastname, $blanc);
imagettftext($fond, 12, 0, 100, 127, $noir, $font, $name);
header ("Content-type: image/jpeg");
imagejpeg($fond);
imagedestroy($fond);
?>