Page 1 of 1

GD not generating image on my online host properly! HELP!!!!

Posted: Mon Jul 13, 2009 9:03 am
by paritycheck
Hi guys, I'm generating an image out of text using php. My code works perfectly on my localhost and the text is generated fine. However for some odd reason on my online host it doesn't generate the whole text just bits and pieces of it. Like if I were to pass the text 'This is some text' to it - it would generate just maybe an S or t.

The code is fine as it works perfectly on my localhost but doesn't run on the online host. It cant be that gd isnt on the host else it would not even generate part of the image.

Whats going on here :(

This is the GD Config on the server - I don't think there is anything wrong with it

Code: Select all

gd
GD Support  enabled
GD Version  bundled (2.0.34 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.2.1
GIF Read Support    enabled
GIF Create Support  enabled
JPG Support     enabled
PNG Support     enabled
WBMP Support    enabled
XBM Support     enabled 
 
I'm just turning email addresses and fone numbers into one image. Heres an image of what the text should look like:
Image

But this is what its rendering on the online:
Image

Also I have noticed that - If I try to create an image out of the text 'P P' it should create the following image which it does on my localhost.

Image

But on the online server its creating the image as so - the space is humongous and distorted. Could this be a hint as to why is it not rendering the text as it should.

Image

Please guys I need help here urgently :(.

Re: GD not generating image on my online host properly! HELP!!!!

Posted: Mon Jul 13, 2009 9:41 am
by Skara
It could be a bug in the version of gd, something to do with the freetype (or other) extension. Could be you're using opentype rather than freetype... could be a number of things.
Post your code.

Re: GD not generating image on my online host properly! HELP!!!!

Posted: Mon Jul 13, 2009 9:55 am
by paritycheck
Here is the code:

Code: Select all

$textval = "This is some text"
$textcolor = "000000";
 
$fontpath= "path/to/my/font/"
$font="arial.ttf";
$size = 9;
$padding= 2;
$bgcolor= "ffffff";
$transparent = 0;
$antialias = 0;
 
$fontfile = $fontpath.$font;
 
$box= imageftbbox( $size, 0, $fontfile, $textval, array());
$boxwidth= 600;//$box[4];
// New lines are denoted by a BR tag 
$textAll = explode("<br/>", ($textval));
 
$boxheight= abs($box[3]) + abs($box[5]);
$width= $boxwidth + ($padding*2) + 1;
$height= $boxheight + ($padding) + 0;
$height = $height*count($textAll);
$textx= $padding;
$texty= ($boxheight - abs($box[3])) + $padding;
 
// create the image
$png= imagecreate($width, $height);
 
$color = str_replace("#","",$bgcolor);
$red = hexdec(substr($bgcolor,0,2));
$green = hexdec(substr($bgcolor,2,2));
$blue = hexdec(substr($bgcolor,4,2));
$bg = imagecolorallocate($png, $red, $green, $blue);    
 
foreach($textAll as $ii=>$vv)
{
    $color = $textcolor;
    $red = hexdec(substr($textcolor,0,2));
    $green = hexdec(substr($textcolor,2,2));
    $blue = hexdec(substr($textcolor,4,2));
    $tx = imagecolorallocate($png, $red, $green, $blue);
    
    $addme = 0;
    if($ii>0)
        $addme = 1.5*$size;
    $texty+=$addme;
    imagettftext( $png, $size, 0, $textx, $texty, $tx, $fontfile, trim($vv) );
 
}
 
 
header("content-type: image/jpeg");
imagejpeg($png);
imagedestroy($png);
exit;
It works great on my localhost but somethings wrong with the online server :( - what should I do here..

Re: GD not generating image on my online host properly! HELP!!!!

Posted: Mon Jul 13, 2009 3:49 pm
by Skara
Wow, yeah, I don't know. I see a few issues with your code, but none that should produce this.

Try replacing imagettftext() with imagestring() and see what happens. That will take out all reliance on the ttf library. Whether it works or not will help pinpoint the problem. (It should fix it.)

Try reuploading your font file in case it got corrupted.

All else fails, write a simplified version that displays a static image without all the calculations for size and color, etc. i.e. write as little code as possible in order to use the imagettftext() function. That should make pinpointing the error even simpler.

Re: GD not generating image on my online host properly! HELP!!!!

Posted: Tue Jul 14, 2009 12:27 am
by paritycheck
Ok when I use imagestring however - the problem of the text being all broken up seems to have solved BUT the image is still showing just a cut out line :( as below. The bottom is supposed to be 5 lines of text but its not even showing one line however it appears it has generated the text in the correct sequence.

Image

Re: GD not generating image on my online host properly! HELP!!!!

Posted: Tue Jul 14, 2009 4:07 am
by paritycheck
The thing I need to add is that this is working perfectly on my localhost - I can't understand whats wrong with the online server :( is there something in code that I should be working around or should I talk to the host - and what should I talk to the host about in the first place here :(

Re: GD not generating image on my online host properly! HELP!!!!

Posted: Tue Jul 14, 2009 7:21 am
by turbolemon
Is your online server setup identical to that of your development machine? If not, it may help to provide information for both systems.

Re: GD not generating image on my online host properly! HELP!!!!

Posted: Tue Jul 14, 2009 8:27 am
by paritycheck
I've posted the GD settings of the online server - but there doesn't seem to be any issue there. Its a shared host - but I'm still perplexed as to why is it not working as it should :( it can't be a code issue as my code works perfectly on my localhost system.

What should I ask the host about in order to fix this issue?