skaterdav85 Posted April 20, 2010 Share Posted April 20, 2010 How do I output an image from a db stored as type blob? I have tried googling it and i can only find scripts that upload images to a db as type blob. The field is called 'cover' and when I did echo $row['cover']; all i get is the binary data. Link to comment Share on other sites More sharing options...
Synook Posted April 20, 2010 Share Posted April 20, 2010 You use a separate script with the relevant Internet Media (MIME) type set. E.g., say you have a script image.php: header("content-type:image/png");$id = (int) $_GET['id'];$result = mysql_query("SELECT cover FROM table WHERE id = $id");$row = mysql_fetch_assoc($result);echo $row['cover']; Then from another script: <img src="image.php?id=1" alt="PHP-generated image"> Link to comment Share on other sites More sharing options...
skaterdav85 Posted April 20, 2010 Author Share Posted April 20, 2010 Thanks! It worked well. How would you be able to get image properties from this, such as width and height? Link to comment Share on other sites More sharing options...
Synook Posted April 21, 2010 Share Posted April 21, 2010 Use the GD library's imagecreatefromstring() to load the image data as a GD resource. Then you can use the various GD functions to check the properties. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.