title: RMagick with a direct form submitted Image from Sinatra
body: <p>I am trying to do something quite simple using <strong>Sinatra</strong> and <strong>RMagick</strong>.</p>
  
  <ol>
  <li>Take a image, through a simple form
  file upload </li>
  <li>Use RMagick to resize it</li>
  <li>Then store it in a database for
  persistence <em>(irrelevant)</em></li>
  </ol>
  
  <p>But after going through the RDocs and endless head banging testing
  I can't seem to get the form image to a RMagick object <strong><em>cleanly</em></strong>.</p>
  
  <p>This is the horrible thing that is currently working for me:</p>
  
  <pre><code>def image_resize(img_data)
      filecount = rand
      writer = File.new("/tmp/#{filecount}.jpg", "w")
      writer.puts(img_data)
      writer.close
  
      resized_image = Magick::ImageList.new("/tmp/#{filecount}.jpg").first
      resized_image.crop_resized!(100,100, Magick::NorthGravity)
      resized.format = 'jpeg'
      resized_image.to_blob
  end
  
  #call the method with my form image data
  image_resize(params[:image][:tempfile].read)
  </code></pre>
  
  <p>So how do I do the obvious right thing and just stick my form image data straight into a RMagick object without having to write and read the disk.</p>
  
  <p>I have tried various ways of reading in Magick::Image and ImageLists but have only got an abundance of errors barfed at me.</p>
  
  <hr>
  
  <p>Thanks for any kind of direction</p>
  
  <p>-1.2.</p>