Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9034601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:31:39+00:00 2026-06-16T08:31:39+00:00

This is the Link I am following to create an image, however my GD

  • 0

This is the Link I am following to create an image, however my GD is installed and working correctly as i tested with the very first example but this code breaks and flag “Image can not be displayed because it contains error” .

CODE –

<?php
//phpinfo();

//Report any errors
ini_set("display_errors", "1");
error_reporting(E_ALL); 

//Set the content type
header('content-type: image/png');

//Create our basic image stream 300x300 pixels
$image = imagecreate(300, 300);
//$image = imagecreatetruecolor(300, 300);
//Set up some colors, use a dark gray as the background color
$dark_grey = imagecolorallocate($image, 102, 102, 102);
$white = imagecolorallocate($image, 255, 255, 255);

//Set the path to our true type font 
//$font_path = 'advent_light';
//$font_path = 'advent_light.ttf';
//$font_path = 'arial';
$font_path = 'arial.ttf';

//Set our text string 
$string = 'Swapnesh!';

//Write our text to the existing image.
imagettftext($image, 50, 0, 10, 160, $white, $font_path, $string);

//Create our final image 
imagepng($image);

//Clear up memory 
imagedestroy($image);
?>

Things I tried and googled but with no solution are as follows – 🙁

  • Checked white/blank spaces before php tag if any.
  • Remove all code and spaces before header() method.
  • Changed imagecreate() to imagecreatetruecolor() as in comments in the code.
  • Checked font_path and set font path as per comments as well.
  • Followed this & this.

My PHP version – PHP Version 5.3.8

Still unable to locate the problem 🙁

enter image description here

Error

Error

EDITS–

version 1.0

this is what im getting on saving.

enter image description here

More Info about image —

enter image description here

on saving the page — this is the name of file saving — create_png.php.png

version 1.1

<br />
<b>Warning</b>:  imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>20</b><br />
<br />
<b>Warning</b>:  imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>23</b><br />

Thanks to @cryptic and @user1711126

Solution —

Font file actually missing, we need to put our .ttf file under the folder to make this code working or set path to make it work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:31:41+00:00Added an answer on June 16, 2026 at 8:31 am

    Save the image file that errors and open it in a text editor like notepad or equivalent and see if any PHP errors are inside it. An error is occurring and outputting text then which corrupts the file. Do that and you will find what the error is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a static library following this link . But I am facing
I have tried to do this refering to following link. http://skypher.com/index.php/2008/07/28/function-list-for-php/ But no success.
I have the following bit of code, simply: $(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({
This link shows how to inject JavaScript code to WebView object in Android. However
I have the following code but my question is about the banner image <!DOCTYPE
following this link i was able to load and read pixels from a .gif.
I am trying to model this relationship following this link http://www.javaworld.com/javaworld/jw-01-2008/images/datamodel.gif Its the usual
Following the advice in this link, Eclipse, classpath and subversion , I have setup
Following How to re-write timthumb.php image url? I was able to create the redirection
I'm using the following code to create divs with random products. The JSON data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.