Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to solve this error

Posted on 2009-07-10
8
434 Views
Last Modified: 2013-12-13
the sent code have these errors

Warning: imagecreatefrompng(button.png) [function.imagecreatefrompng]: failed to open stream: No such file or directory in D:\xampp\htdocs\test\05.php on line 6

Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in D:\xampp\htdocs\test\05.php on line 7

Warning: imagesx(): supplied argument is not a valid Image resource in D:\xampp\htdocs\test\05.php on line 12

Warning: imagesy(): supplied argument is not a valid Image resource in D:\xampp\htdocs\test\05.php on line 13

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in D:\xampp\htdocs\test\05.php on line 16

Warning: imagettftext() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\test\05.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\test\05.php:6) in D:\xampp\htdocs\test\05.php on line 20

Warning: imagepng(): supplied argument is not a valid Image resource in D:\xampp\htdocs\test\05.php on line 21

I think there is something disabled
please help me turn it on
<?php
 if (isset($_GET['message'])) {
   // load font and image, calculate width of text
   $font = 'times';
   $size = 12;
   $im = ImageCreateFromPNG('button.png');
   $tsize = imagettfbbox($size,0,$font,$_GET['message']);
 
   // center
   $dx = abs($tsize[2]-$tsize[0]);
   $dy = abs($tsize[5]-$tsize[3]);
   $x = ( imagesx($im) - $dx ) / 2;
   $y = ( imagesy($im) - $dy ) / 2 + $dy;
 
   // draw text
   $black = ImageColorAllocate($im,0,0,0);
   ImageTTFText($im, $size, 0, $x, $y, $black, $font, $_GET['message']);
 
   // return image
   header('Content-type: image/png');
   ImagePNG($im);
   exit;
 }
?>
<html>
  <head><title>Button Form</title></head>
  <body>
 
    <form action="<?= $PHP_SELF ?>" method="GET">
      Enter message to appear on button:
      <input type="text" name="message" /><br />
      <input type="submit" value="Create Button" />
    </form>
 
  </body>
</html>

Open in new window

0
Comment
Question by:hatem_from_mesr
  • 4
  • 2
  • 2
8 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24826099
Run this script and look to see if you have GD enabled.
<?php phpinfo(); ?>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24826131
Then go look at your directories and find out why this button.png file is missing.  You may be looking at the wrong directory.  You can print out the contents of getcwd() to see what directory your script is looking in.

Not sure, but I think all the other errors are downstream issues caused by the failure of this command:
ImageCreateFromPNG('button.png');

HTH, ~Ray
0
 
LVL 4

Expert Comment

by:termlimit
ID: 24826358
The button.png needs to be located in a place where the server is reading.  Typically this is passed in with a full path to the file not just a file name.

If you are trying to create it from scratch you can do the following to make that happen:

You need to make sure that the image has a valid resource before continuing.  If not you will get the above warnings that you see.
<?php
if( isset($_GET['message']) ) {
    // load font and image, calculate width of text
    $font = 'times';
    $size = 12;
    $im = ImageCreateFromPNG('button.png');
    if(!$im) {
        /* Create a blank image */
        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);
 
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
    }
    $tsize = imagettfbbox($size,0,$font,$_GET['message']);
 
    // center
    $dx = abs($tsize[2]-$tsize[0]);
    $dy = abs($tsize[5]-$tsize[3]);
    $x = ( imagesx($im) - $dx ) / 2;
    $y = ( imagesy($im) - $dy ) / 2 + $dy;
 
    // draw text
    $black = ImageColorAllocate($im,0,0,0);
    ImageTTFText($im, $size, 0, $x, $y, $black, $font, $_GET['message']);
 
    // return image
    header('Content-type: image/png');
    ImagePNG($im);
    exit;
}
?>

Open in new window

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:hatem_from_mesr
ID: 24829848
Ray_Paseur,
>>>Run this script and look to see if you have GD enabled.
it's enabled
0
 

Author Comment

by:hatem_from_mesr
ID: 24829865
when I put the button.png file
there is those errors

Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in D:\xampp\htdocs\test\05.php on line 7

Warning: imagettftext() [function.imagettftext]: Invalid font filename in D:\xampp\htdocs\test\05.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\test\05.php:7) in D:\xampp\htdocs\test\05.php on line 20
0PNG  IHDR_Æâô`¬IDATX&J8± ¬ Q0.&¾®`iD<X©¯O¢×Bq¯"T?B¹6‘ôc=Á4¬N M.6¸{_çÆaH²JG[{vÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuÆuH÷êS"b PM &û ¼w(/T8|;IEND®B`
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24831863
So the warning indicates that there is something wrong with the contents of $_GET["message"] - it is not a font filename, apparently.
0
 
LVL 4

Accepted Solution

by:
termlimit earned 500 total points
ID: 24832128
"times" isn't a font.  Check the PHP docs for the proper way to use this.  'arial.ttf' is one example.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24832148
Man page here.  Font file name can be URL.
http://us2.php.net/manual/en/function.imagettfbbox.php
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Syntax Error 4 32
How to submit record from external php form to a Sharepoint list? 5 55
PHP Mail error 3 26
Link failure 16 32
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question