title: How to base64 encode image in linux bash / shell
body: <p>I'm trying to base64 encode an image in a shell script and put it into variable:</p>
  
  <pre><code>test="$(printf DSC_0251.JPG | base64)"
  echo $test
  RFNDXzAyNTEuSlBH
  </code></pre>
  
  <p>I've also tried something like this:</p>
  
  <pre><code>test=\`echo -ne DSC_0251.JPG | base64\`
  </code></pre>
  
  <p>but still with no success. </p>
  
  <p>I want to do something like this:</p>
  
  <pre><code>curl -v -X POST -d '{"image":$IMAGE_BASE64,"location":$LOCATION,"time_created":$TIMECREATED}' -H 'Content-type: text/plain; charset=UTF8' http://192.168.1.1/upload
  </code></pre>
  
  <p>I found this <a href="http://www.zzzxo.com/q/answers-bash-base64-encode-script-not-encoding-right-12290484.html" rel="noreferrer">http://www.zzzxo.com/q/answers-bash-base64-encode-script-not-encoding-right-12290484.html</a></p>
  
  <p>but still have had no success.</p>