title: Create a image file from binary data in Ruby
body: <p>I am able to access the binary data of a file and store it in a varible like this</p>
  
  <pre><code>s = File.binread("sample_22122015_03.jpg")
  bits = s.unpack("B*")[0]
  </code></pre>
  
  <p>where bits has data like this "101001001010100100......."</p>
  
  <p>However, I want to do some changes and again write the binary data back to a new image, but I am unable to.</p>
  
  <p>I am using</p>
  
  <pre><code>File.open('shipping_label_new.jpg', 'wb') do|f|
  f.write(Base64.decode64(bits))
  end
  </code></pre>
  
  <p>but it's not working and I see that the image is corrupt. </p>