Jump to content

Recommended Posts

Hi!

 

the following code doesn't working:

 

<?php

header("Content-type: image/png");
$string = $_GET['text'];
$im     = imagecreatefrompng("images/button1.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);

?>

 

I just copy and pasted it: http://php.net/manual/en/image.examples-png.php

 

I created the folder images and added an image with the name "button1.png" and I'm passing the text parameter "php?text=text", but the page only display this: http://localhost/path/file.php?text=text

Link to comment
https://forums.phpfreaks.com/topic/143152-solved-imagecreatefrompng-dont-work/
Share on other sites

Note, localhost is local to your computer. We cannot see that.

i'm not that newbie  ;D.

 

I think gd is installed, because I can create images, but not from png file.

eg:

 

<?php
function LoadPNG($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefrompng($imgname);

    /* See if it failed */
    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);

        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

header('Content-Type: image/png');

$img = LoadPNG('bogus.image');

imagepng($img);
imagedestroy($img);
?>

 

this code enter in the "if", because it fails in create the image from the png file.

 

Note, localhost is local to your computer. We cannot see that.

i'm not that newbie  ;D.

 

Well why did you link to it then? lol.

 

Anywho, i'm confused. Bogus.image obviously isn't a png image. So surely the script is performing correctly?

Do a phpinfo I bet you that PNG Support is not enabled.

 

And as far as my statement, sorry to implicate that, but you linking to it saying "It only displays this" sounded to me like you expect us to be able to click on it and see what you mean.

And as far as my statement, sorry to implicate that, but you linking to it saying "It only displays this" sounded to me like you expect us to be able to click on it and see what you mean.

 

I didn't put the link to you access. I just write what displayed in the page, but as it start with "http:" it created the link automatically!

I didn't put the link to you access. I just write what displayed in the page, but as it start with "http:" it created the link automatically!

 

Sounds like you got some other issues, maybe with Apache....I do not know why it would show the url inside the page... ???

 

Anyhow did you checkout the phpinfo?

phpinfo();

 

....

 

gd

GD Support enabled

GD Version bundled (2.0.34 compatible)

FreeType Support enabled

FreeType Linkage with freetype

FreeType Version 2.1.9

T1Lib Support enabled

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

...

 

I'm using IIS (not by my will). Maybe some access property, anyone?

I'm using IIS (not by my will). Maybe some access property, anyone?

 

Mmm, thats a pitty. I do not use IIS, I tested your script on my apache server and it worked like a champ....but I was using a 284x156 button1.png image, whether that has something to do with it I do not know.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.