play! scala file resource handling and image resizing
Upcoming SlideShare
Loading in...5
×
 

play! scala file resource handling and image resizing

on

  • 1,594 views

file resource and image resize plugin for play! 2 framework in scala. storing files like amazon s3 bucket and resize images on the fly.

file resource and image resize plugin for play! 2 framework in scala. storing files like amazon s3 bucket and resize images on the fly.

Statistics

Views

Total Views
1,594
Views on SlideShare
902
Embed Views
692

Actions

Likes
1
Downloads
4
Comments
0

10 Embeds 692

http://www.pichsenmeister.com 274
http://3x14159265.tumblr.com 229
http://localhost 62
http://www.scala-vienna.org 52
http://scala-vienna.org 40
http://www.slideee.com 30
http://www.arfadia.com 2
http://dev.scala-vienna.org 1
https://twitter.com 1
https://assets.txmblr.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    play! scala file resource handling and image resizing play! scala file resource handling and image resizing Presentation Transcript

    • file resource handling & image resizing in play! (scala) by david pichsenmeister
    • play-res & play-scalr for play! framework 2 developed by @LeonRadley
    • play-res like amazon s3 bucket computes sha1 hash of file and uses it as pathname
    • dependencies val appDependencies = Seq( "se.digiplant" %% "play-res" % "1.0" ) val main = play.Project(appName, appVersion, appDependencies).settings( // to simplify the reverse routing templatesImport ++= Seq("se.digiplant._") )
    • conf/application.conf # Resource plugin save directory # is relative to app, but can be absolute to filesystem also res.default=res res.images=res/images conf/routes GET /res/:file se.digiplant.res.ResAssets.at(file) GET /images/:file se.digiplant.res.ResAssets.at(file,“images”)
    • upload def upload = SecuredAction(true) { implicit request => val file = for { body <- request.body.asMultipartFormData uploaded <- body.file("file") } yield uploaded file match { case Some(f) => { val id: String = Res.put(f.ref.file) Ok(Json.obj("url" -> id)) } case _ => BadRequest } }
    • reverse routing <img src="@res.routes.ResAssets.at ("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg")" alt="" /> <img src="@res.routes.ResAssets.at ("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg", "images")" alt="" /> direct http://www.sharedspaces. at/res/cf342662c630a41f0dcf19314a35f82e5abbc9c4.jpg
    • play-scalr image resizing “on-the-fly” http://sharedspaces.at/{{width}}/{{height}}/ {{mode}}/file.jpg different modes: ● ● ● ● ● automatic fit_exact fit_to_width fit_to_height crop
    • dependencies val appDependencies = Seq( "se.digiplant" %% "play-scalr" % "1.0.1" ) conf/application.conf # define cache, so they only need to be resized once res.scalrcache=res/scalr # Tell scalr to use scalrcache source we just created scalr.cache=scalrcache conf/routes GET /res/:width/:height/:mode/:file se.digiplant. scalr.ScalrResAssets.at(width: Int, height: Int, mode: String, file)
    • reverse routing <img src="@scalr.routes.ScalrResAssets.at ("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg", 150, 100, "crop")" alt="" /> direct http://www.sharedspaces. at/res/150/100/crop/cf342662c630a41f0dcf19314a35f82e5abbc9c 4.jpg
    • resources http://leon.radley.se/project/ https://github.com/digiPlant/play-res https://github.com/digiPlant/play-scalr
    • thanks! feel free to add me on: .../3x14159265