title: Javascript image compression before AES encrypt
body: <p>I need to AES encrypt fileupload images with javascript before storing to the server but I'm running into LONGTEXT limitations when trying to store as custom field in MySQL. That method involved converting image to base64 and then encrypting.</p>
  
  <p>I'm looking for a method to achieve the smallest string possible from that image upload before encrypting. Or at the very least how to reduce the image under a specified byte maximum.</p>
  
  <pre><code>&lt;input id="foo" type="file" /&gt;
  </code></pre>
  
  <p>Encrypt with <a href="https://github.com/brix/crypto-js" rel="nofollow noreferrer">CryptoJS</a></p>
  
  <pre><code>$(document).on("change", "#foo", function() {
      var chatImg = $(this).val();
  
      // COMPRESS IMAGE
  
      var keyAES = "123456789";
      var eImg = CryptoJS.AES.encrypt(chatImg, keyAES).toString();
      console.log(eImg);
  });
  </code></pre>
  
  <p>Note: I've searched far and wide for a solution but the only ones I found involved set image widths/heights</p>