Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


storing image in database directly or as base64 data


storing image in database directly or as base64 data  using -'mysql,database,image,imagemagick,base64'

The common method to store images in database is to convert image to base64 data then storing. This process will increase the size 33%. Alternatively it is possible to directly store image BLOB; for example:

$image = new Imagick("image.jpg");
$data = $image->getImageBlob();
$data = $mysqli->real_escape_string($data);
$mysqli->query("INSERT INTO images (data) VALUES ('$data')");


and display the image with

<img src="data:image/jpeg;base64,' .  base64_encode($data)  . '" />


By the latter method, we save 1/3 storage space. Why storing base64 data into database is the common method for storing images in database?

UPDATE: There are many debates about advantages and disadvantages of storing images in databases, and most people believe it is not a practical approach. Anyway, here I assume we store image in database, and discussing the best method to do so.
    

asked Sep 22, 2015 by vijayshukla80
0 votes
27 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...