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 719871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:41:37+00:00 2026-05-14T05:41:37+00:00

Using PHP’s Image and GD functions you can use the following method to finally

  • 0

Using PHP’s Image and GD functions you can use the following method to finally output the php image

imagepng($image);

Sometimes, for whatever reason the image may not be displayed typically the error is not with the image but with the actual php functions not executing successfully. However this causes a blank image to be returned which doesn’t help me.

What I want to know is, is there a way to detect a blank or an invalid image and create a new image, write the errors to the new image using imagestring() and then display this new (debug) image instead.

for example, a successfully displayed image with no errors:

$image  = imagecreate(256, 256); //create image
imagecolortransparent($image, $BLUE); //set transparent
imagefilledrectangle($image, 0, 0, 256, 256, $BLUE); //fill with 'transparent colour'

//Draw a border round the image
imageline($image, 0, 0, 0, 255, $Black);
imageline($image, 0, 0, 255, 0, $Black);
imageline($image, 255, 0, 255, 255, $Black);
imageline($image, 0, 255, 255, 255, $Black);

imagestring($image, 1, 10, 10, "I am an image!", $Black);

imagepng($image);
imagedestroy($image);

but if I then introduce some errors in the php script that may or may not be to do with the actual image creation then the php script fails and the image will not be visible…

$image  = imagecreate(256, 256); //create image
imagecolortransparent($image, $BLUE); //set transparent
imagefilledrectangle($image, 0, 0, 256, 256, $BLUE); //fill with 'transparent colour'

//Draw a border round the image
imageline($image, 0, 0, 0, 255, $Black);
imageline($image, 0, 0, 255, 0, $Black);
imageline($image, 255, 0, 255, 255, $Black);
imageline($image, 0, 255, 255, 255, $Black);

imagestring($image, 1, 10, 10, "I am an image!", $Black);

/* I am here to cause problems with the php script 
** and cause the execution to fail, I am a function 
** that does't exist...
**
** and I am missing a semi colon! ;)*/
non_existant_function() 

imagepng($image);
imagedestroy($image);

At this point I want to create a new image like above but in replacement of the I am an image! text I would put the actual error that has occured.

  • 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-05-14T05:41:38+00:00Added an answer on May 14, 2026 at 5:41 am

    What you want to do is catch PHP errors, not detect a “blank image”. You can use set_error_handler() to define a custom callback that’s called when an error occurs.

    Things such as parse errors are something you should debug before publishing your code, but this should help you detect random errors (database connections dying, whatnot).

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

Sidebar

Related Questions

Using PHP I'm trying to download/save the following image: http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428 When you load this
Using PHP, given a URL, how can I determine whether it is an image?
Using PHP on Linux, I can just use the is_link() function to detect whether
Using PHP, I can convert MySQL data or static table data to csv, Excel,
Using PHP, can I post content to a Facebook page when I add something
Using PHP 5.3.8. I'm attempting to implement two functions, save($adoption) which serializes an Adoption
Using PHP, If I have a model (a class) where I various queries, whatever
Using PHP's proc_open() , I can start a process, read from STDOUT and STDERR
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Using PHP (other languages, using common built-ins are welcome), how can I get a

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.