Reputation: 1329
I am creating a Play 2.2 application where depending on the URL, I need to retrieve an image from S3 and render it to the user.
I am aware that I can just render the image after I get it, but I want to embed it in a web page so I can center it and display some more information if necessary.
I see two possible options:
Option A:
Option B: (preferred approach)
Is the second option possible? If so, is it an acceptable approach or would the performance hit not be worth it?
Upvotes: 1
Views: 1046
Reputation: 55798
Disclaimer: It is possible, anyway as your question is rather 'opinion based' - the answer will be also just a suggestion (or rather portion of suggestions).
First, use some graphic library for processing images, i.e. we are using currently GraphicsMagick (GM) + gm4java (sorry, have no idea what is correct lib for Scala) for file cropping, fast, nice, does the job as expected.
In our case we need to avoid the possibility to display origin/cropped images to unauthorized users, therefore we are returning it with Play's return ok(new File(path))
after checking the access rights, but for public assets you can also just use i.e. some HTTP server which will just handle delivering the images or even send cropped images back to S3 and then use it's URL directly in src
attribute.
Approach is quite simple:
Keep in mind that's rather bad (means: slow and expensive) option to fetch S3 file to Play app and processing it every time when there's a request for cropped version, therefore add some additional HDD space into your pricing plan and keep origins
and cropped
as long as possible at the destination machine.
Also tip: removing color profile
(with GM) from result thumbnail(s) will lower it's size so you'll save additional dollars transfer/storage fees.
Upvotes: 1