You'll need the GD library that comes with PHP.
But queries returning a LONG BLOB can get mighty slow - especially if you've got more than one result in the set. Why don't you just put the path to the graphic file in the db? If you're worried about people accessing the photos directly, you could use a .htaccess file, then use the cURL library (also comes installed) to access it from your script.