1

I searched a lot, perhaps inefficiently, but I can not find information on how to scale the image stored in the database?

I'm inserting my image as

"0xffd8ffe110e94578696..."

after ussing unpack:

$data = file_get_contents($_FILES['image']['tmp_name']);
$data = unpack('H*',$data);
$data = '0x'.$data[1];

And then I can preview my image using base64_encode:

<img src="data:image/png;base64,/9j/4RDpRXhpZgAATU0AKgAAAAg...e6/9k=">

Probably informations above are unnecessary, becasue it's obvious how to send img to DB and how to preview that image. But maybe it helps you to understand me.

So is there any way to achieve that?

keid
  • 91
  • 1
  • 10
  • 1
    possible duplicate of [How do I resize pngs with transparency in PHP?](http://stackoverflow.com/questions/279236/how-do-i-resize-pngs-with-transparency-in-php) – Gadoma May 10 '14 at 18:46
  • I think it's about img which are not stored in DB. – keid May 10 '14 at 18:49
  • @keid: well but it contains the answer: use a library for this. Because the OP showed PHP code and the image is a png that should be the way to go. – VMai May 10 '14 at 18:54
  • @VMai Library that will 'transfer' base64 code to png? – keid May 10 '14 at 19:06
  • @keid base64_decode() should be applied first ... – VMai May 10 '14 at 19:11

1 Answers1

0

Scaling your image is not a function of your database system. Instead, it's a function of your host language.

You need to retrieve the image from the database in which you've stored its byte stream as a binary large object (blob). You then need to use some software or other to rescale it. This most likely requires decoding the byte stream, resampling the image, and encoding a byte stream for a new image.

You then can store it back into the database. Depending on what your application needs, you might choose to UPDATE the row with the original blob, or INSERT another row with the new blob.

O. Jones
  • 103,626
  • 17
  • 118
  • 172