tags:

views:

56

answers:

4

Hi!

I want to make a unique forum signature from my latest watched animes in PHP. These are contained in an RSS feed. On my local apache server, the image is generated well, but as I upload it onto a server, I get an error, the picture isn't generated at all.

Here is my code and I wonder what's the problem since neither Dreamweaver CS5 or phpDesigner 7 don't show any errors, although if I press the Run button in phpDesigner, I get an error, but I don't know what it means. The error is the following:

Line: 6 - Fatal error: Call to undefined function imagecreatefrompng() in [php's path here]

So the code is the following:

<?php
    // title & description arrays
    $titleCuts = array();
    $descCuts = array();
    // bg image
    $bgimg = imagecreatefrompng('sig_robin.png');
    // colors 
    $white = imagecolorallocate($bgimg, 255, 255, 255);
    $textColor = imagecolorallocate($bgimg, 245, 193, 9);
    $shapeColor = imagecolorallocate($bgimg, 27, 20, 0);

    // sxe <- xml url
    $sxe = new SimpleXMLElement('http://myanimelist.net/rss.php?type=rw&amp;u=fema', NULL, TRUE);

    // shape
    imagefilledrectangle($bgimg, 255, 20, 567, 279, $shapeColor);

    // TEXTS
    imagettftext($bgimg, 20, 0, 263, 52, $white, "my.ttf", "Latest Watched:");
    // episodes' text
    for($i=0;$i<5;$i++) 
    {
        // title cut and joint
        $titleCuts = explode(' ', $sxe->channel->item[$i]->title, -2);
        $titleCut = implode(' ',$titleCuts);
        // description (ep) cut and joint
        $descCuts = explode(' ', $sxe->channel->item[$i]->description);
        // output
        imagettftext($bgimg, 10, 0, 270, 77+($i*45), $textColor, "my.ttf", $titleCut);
        imagettftext($bgimg, 10, 0, 270+(strlen($titleCut)*7.2), 92+($i*45), $textColor, "my.ttf", "ep. ".$descCuts[2]);
    }

    header('Content-type: image/png');    
    // generating image
    imagepng($bgimg);
?>

Thanks in advance.

Edit:
As I removed the header, now I get a lot of error that it can't find the font file, but I'm dead sure that I wrote it correctly.

They look like this:

Warning: imagettftext() [function.imagettftext]: Could not find/open font in ... on line 19

+1  A: 

This means that GD either wasn't compiled into PHP or hasn't been loaded. First, check your php.ini, the path for which you can find with phpinfo() for extension=php_gd2.dll and make sure it's not commented out with a semicolon. After changing the setting, restart the webserver, then look at phpinfo() again to see if GD is loaded.

John Douthat
A: 

To use this function (imagecreatefrompng) your php needs to be installed with the GD extensions (for more information see this page.

To check what is / isn't install create a php file on your local server with just:

And then compare the image (GD) sections to the same file running on your server.

Note that if you are on a shared hosting server you'll probably have to contact their admins to install / configure this for you.

Oren
+1  A: 

IF imagecreatefrompng is not defined, most likely the GD library is not installed, or broken, see: http://php.net/manual/en/image.installation.php

Don't be alarmed by the 'you have to configure and rebuild PHP', normally the package manager of your OS can easily add GD support by installing an extra package.

Wrikken
+2  A: 

Ok, the solution for the second problem is that its a php bug http://bugs.php.net/bug.php?id=41336

But its easy to solve, in following way:

Put a ./ before every *.ttf file like in following example:

imagettftext(IMAGE, 0, 0, 0, 0, TEXT_COLOR, "./ttf_file.ttf", TEXT);
Nort
Damn... I wouldn't think it was the problem, but it's solved now. :o Thanks!
fema
you're welcome.Another thing i would do is, put an @ character at the beginning of the `@imagecreatefrompng(...)` because it can happen that you load a bad converted image, and you get an error message what causes that your image wont show
Nort
Thanks for the tip! ;)
fema