PHP imagettftext Is Not Showing Text - php

Website:
https://bimmr6696.000webhostapp.com/signs/Sign.php?Line1=&Line2=asd&Line3=&Line4=
PhpInfo:
https://bimmr6696.000webhostapp.com/signs/test.php
Currently I have the following code:
$img = LoadPNG('sign.png');
//$font = imageloadfont('minecraft.ttf');
// Add the text
imagettftext($img, 20, 0, 5,5, $black, 5, "Test Text");
imagestring($img, 5, 5, 50, 'Test Text', $text_color);
// Create image instances
$dest = imagecreatetruecolor(80, 40);
// Copy
imagecopy($dest, $img, 0, 0, 20, 13, 80, 40);
// Set the content type header - in this case image/png
header('Content-type: image/png');
// Output the image
imagejpeg($img);
imagejpeg($dest);
imagedestroy($dest);
imagedestroy($img);
When I use imagestring I'm able to get the text to show, but the text is too small which causes me to need imagettftext, although nothing shows when I use this. I've just about run out of ideas to try and solve this and so any help would be very appreciated.
TLDR: I need to either find out why imagettftext doesn't work or find a way to change font size with imagestring
Deleted everything then retyped it all out and for some reason that seemed to fix it... Because this isn't an actual answer I'm not going to post it below...

Related

Creating image with fix background and randomly displayed text from a pre-defined list

I would like to create a script which is generating an image with one fix background image but display a randomly selected sentence on the image from a list which is previously given in the script.
So far I have a base and I've tried many variations for the random text, but none of them worked until this time.
Here is the script itself:
<?php
header('Content-type: image/png');
$text = 'The text which will be displayed';
$background_path = 'assets/bg_image.jpg';
$image = imagecreatetruecolor(1280, 720);
$background = imagecreatefromjpeg($background_path);
$color = imagecolorallocate($image, 255, 255, 255);
$title_sizes = imagettfbbox(24, 0, 'assets/roboto-medium.ttf', $text);
$title_height = $title_sizes[3];
$title_width = $title_sizes[4];
imagecopy($image, $background, 0, 0, 0, 0, 1280, 720);
imagettftext($image, 24, 0, (640 - $title_width / 2), (360 - $title_height / 2), $color, 'assets/roboto-medium.ttf', $text);
imagepng($image);
imagedestroy($image);
imagedestroy($background);
?>
So the thing is that the line "$text" allows only one sentence to be displayed. I would like to have multiple lines (various sentences) instead which will be displayed on the given background image randomly upon refresh.
Can you please help me to solve this problem?
Thank you very much in advance!
Regards,
Adam

PHP - imagettftext not working

I am trying to generate images containing data from my database, and I want to use a custom font for it, so I looked up the imagettftext. I am following its syntax, but it's not printing anything. What am I doing wrong?
When I use imagestring it works fine. But that does not use any custom font.
I have placed my font.tff file in the same folder as my script. Here is my code:
header('Content-Type: image/png');
$image = #imagecreate(400, 110);
$backgrund = imagecolorallocate($image, 70, 130, 180);
$textcolor = imagecolorallocate($image, 255, 255, 255);
$font = 'font.ttf';
// TTF
imagettftext($image, 10, 0, 15, 15, $textcolor, $font, 'Test TTF');
// Normal text
imagestring($image, 2, 15, 30, 'Test Normal Font', $textcolor);
imagepng($image, 'images/test.png');
imagedestroy($image);
Am I missing something? The first line is completely blank. I also tried adjusting the font size (it maybe is different than regular imagestring?) but still nothing. The font is a .ttf font file.

"z-index" in php GD

In css, we have a property called "z-index", what is the same in PHP GD and Image Functions to control the "z-index"?
I've been searching but I can't find one, please help.
Thankyou
there nothing existing like z-index in php GD library
but there several ways to overlap image over image or text over image
$redimg = imagecreatetruecolor(100, 100);
$image = imagecreatefrompng('image.png');
// sets background to red
$red = imagecolorallocate($redimg, 255, 0, 0);
imagefill($redimg, 0, 0, $red);
// Merge the red image onto the PNG image
imagecopymerge($image, $redimg, 0, 0, 0, 0, 100, 100, 75);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
imagedestroy($redimg);
here one example, or let me know, what exactly you trying to do, I will help you
There's more information here.

Error while using imagecreate function

<?php
header("Content-Type: image/png");
$im = #imagecreate(110, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
When i executed the above code i have got an error like this
"The image can't be displayed because it contains errors "
Same error shows in server also
I'm going to go out on a limb here and guess you have some sort of content before and / or after your PHP tags.
Make sure your file starts with <?php with nothing before it (you may need to check for a byte order mark).
Also, omit the closing ?> tag. You don't need it and it will solve any trailing whitespace issues.

Images are not shown in php

I am new in using Php with Images.
I had found the code to display Image
<<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// Save the image as 'simpletext.jpg'
imagejpeg($im);
// Free up memory
imagedestroy($im);
?>>
But firefox show some bogus code instead of that Image.here is the link to the Image that Firefox shows
http://tinypic.com/r/htw6cm/7
Here is the link to the Image
What are you seeing the the "bytes" of an image. By default your browser will think that your script is about to print some text. So you end up seeing some strange characters.
Since you are printing not text, but image, you need to tell the browser that the contents of your script will be an image. You can do this by sending a header like that:
<?php
header("Content-Type: image/jpeg"); // treat the script as an image
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// Save the image as 'simpletext.jpg'
imagejpeg($im);
// Free up memory
imagedestroy($im);
Use
<?
header('Content-type: image/jpg');
at beginning of your script to send an header for images.
so the browser will handle the php output as jpg-image-data
header('Content-type: image/jpg');
not at beginning of your script, but right before starting actual output, i.e on the line above imagejpeg($im);
so, it will let you to see an error if any occurred
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
//send header
header('Content-type: image/jpg');
//output an image
imagejpeg($im);
also I removed some mistakes, errors and useless operators

Categories