title: How can I compress BLOB data in sqlite database in order to reduce its size?
body: <p>I have an sqlite database that contains <strong>BLOB data.</strong></p>
  
  <p>Each BLOB field contains an <strong>image.</strong></p>
  
  <p>(Specifically this database was created by Maperitive, a tool that generates
  <a href="http://wiki.openstreetmap.org/wiki/MBTiles" rel="nofollow">mbtiles</a>)</p>
  
  <p>I would like to <strong>reduce the size of each BLOB field</strong>, in order to reduce the size of the sqlite database.</p>
  
  <p>What I've done till now is:</p>
  
  <p>I have created a PHP script that </p>
  
  <ul>
  <li><p>1) reads the BLOB fields,converts them to images (.jpgs) and stores the images in a new directory named 'BLOB2IMAGES'.</p>
  
  <pre><code> &lt;?php      
        file_put_contents("./BLOB2IMAGES/". $currentImage, $BLOB_DATA);
   ?&gt;     
  </code></pre></li>
  <li><p>2) Afterwards, I use an external tool named<br>
  <a href="http://www.imagemagick.org/" rel="nofollow">ImageMagick</a>. This tool has several commands in order to modify an image. I use the <strong>mogrify command</strong> that <strong>overwrittes</strong> the<br>
  images by modifying the quality of the images.</p>
  
  <p>In that case the size 
  of the images is reduced</p>
  
  <pre><code>  mogrify -format jpg -quality 75% -path "C:\BLOB2IMAGES" "C:\BLOB2IMAGES\*.jpg"
  </code></pre></li>
  <li><p>3) Then I have a created a second PHP script that reads the<br>
  <strong>BLOB2IMAGES directory</strong>, converts each compressed image to a byte array and stores
  the byte array in the sqlite database. (<strong>Attention</strong>:I have created 
  a new sqlite database in order to store the 'new' BLOB data with the reduced size).</p>
  
  <pre><code> &lt;?php
        $byte_array_of_Compressed_image =file_get_contents(("./BLOB2IMAGES/". $compressedImage);
   ?&gt;
  </code></pre></li>
  </ul>
  
  <p>I noticed that in the <strong>1st  conversion of the BLOB data to images</strong> (.jpgs) the quality of the produced images  is not so good and I don't like that. Then I created a simple JAVA program, that converts the BLOB data to  images and again I noticed thet the quality was not so good.</p>
  
  <p>Generally, I would like to reduce the size of the BLOB data, so I followed the previous steps.
  Is there any other way in order to reduce the size of the BLOB data?
  Any tool or any additional extension?
  Shall I use a different approach than the one I have already used?</p>
  
  <p>I would be glad if you could give me solutions or ideas related to my problem.</p>
  
  <p>Thanks, in advance</p>