title: Play Framework: How to resize and convert to JPG an image after upload
body: <p>The following code snippet saves an uploaded image in the database:</p>
  
  <pre><code>object MyController extends Controller {
  
    def upload = Action(multipartFormDataAsBytes) { request =&gt;
      request.body.files foreach {
        case FilePart(key, filename, contentType, bytes) =&gt;
        ...
        // store file in MongoDB GridFS
        ...
      }
      Ok("done")
    }
  }
  </code></pre>
  
  <p><code>bytes</code> contains the uploaded image to be saved in the database... but before actually saving it I need to:</p>
  
  <ol>
  <li>Determine the size of the image and in case resize it</li>
  <li>Determine the type of the image and in case convert it to JPG</li>
  </ol>
  
  <p>Considering that I'll deploy my application to Heruku and I don't know if they installed ImageMagic on their servers, is there any library that let me resize and convert images without having to install native libraries?</p>
  
  <p>I know there is <a href="http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/" rel="nofollow">imgscalr</a> &ndash; a pure Java 2D library &ndash; that provides functionality for resizing images... but I also need to convert them to JPG.</p>
  
  <p>Thanks.</p>