The following code snippet saves an uploaded image in the database:
object MyController extends Controller {
def upload = Action(multipartFormDataAsBytes) { request =>
request.body.files foreach {
case FilePart(key, filename, contentType, bytes) =>
...
// store file in MongoDB GridFS
...
}
Ok("done")
}
}
bytes
contains the uploaded image to be saved in the database... but before actually saving it I need to:
- Determine the size of the image and in case resize it
- Determine the type of the image and in case convert it to JPG
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?
I know there is imgscalr – a pure Java 2D library – that provides functionality for resizing images... but I also need to convert them to JPG.
Thanks.