GD lib Problem

software development


Hi all, I’m new in this web corner :slight_smile:

I have a “little” problem with GD libraries…

I’m coming from another hoster and my scripts, there, run fine…

I have images stored on the mysql db and everytime I need to output them I use, obviously, the code below:

// Code

$photo = db query result

$src = imagecreatefromstring($foto);


// End Code

Unfortunately the output is…nothing…

You can see it here:

I just see the content of the alt tag…

I controlled the php configuration and all seems to be ok…

Any advice…?

P.S. Sorry for my insipid English :frowning:


this may sound awfully obvious but check the variable names! you are storing the query as $photo and using GD with argument $foto, that should never work

by the way… storing the image inside the database is extremely inefficient. You should keep set up your table with references to the files and then generate the image accordingly

for instance, set a table “images” with fields ‘id’ and ‘filename’ so it looks like:

‘id’ 'filename’
1 images/image1.jpg
2 images/image2.jpg

the query the db:
$query = mysql_query(SELECT filename FROM images WHERE id = ‘$id’);

$result = mysql_fetch_array($query);


$src = imagecreatefromjpg($result[‘filename’]);

this releases A LOT of stress from the database. Your site will load much faster and waste much less cpu resources

additionally, remember to always have the script set the appropriate headers before outputting anything, including of course the image itself