0

I'm working on a PHP project, and I record Images DATA URI in a table called "Images", the thing is that that long string takes lot of place for nothing so its heavy to load.

My questions :

  1. How can I resize a Data URI image using PHP (knowing that the input and output wanted will be both DATA URI)
  2. Is there any function or something alike that can compress the DATA URI before put it on my MySQL Database ? (Compress decompress)
Youssef
  • 401
  • 1
  • 5
  • 23
  • A Data URI is base 64 encoded system which is 25% bigger than a regular image. I don't think you can compress a data uri to save space. If there was any method to compres data uri I'm sure they would already apply it to regular image compression. – Ergec Jan 28 '14 at 17:24

1 Answers1

0

There is a library that will do this, you can get it here.

If you want to roll your own solution, PHP allows you to open data URIs with the various file* functions. If you don't mind saving the file to disk while you work on it, you can just do this:

$fileName = md5($dataURI);
file_put_contents($fileName, file_get_contents($dataURI));

Then you can use your preferred image processing library to manipulate the image. To send it again as a data URI, you can use the technique outlined here. Then, delete the temporary file and you're done.

Matt
  • 1,287
  • 2
  • 11
  • 25