val appDependencies = Seq(
"se.digiplant" %% "play-scalr" % "1.1.2"
)
// To simplify the reverse routing we can import the digiPlant namespace
TwirlKeys.templateImports += "se.digiplant._"
# Resource plugin save directory
# is relative to app, but can be absolute to filesystem also
res.default=res/default
# Scalr image cache location (This is simply another play-res source location)
# All resized images get cached here so they only need to be resized once
res.scalrcache=res/scalr
# Tell scalr to use scalrcache source we just created to cache it's images
scalr.cache=scalrcache
# Dynamic image scaling
GET /res/:width/:height/:file se.digiplant.scalr.ScalrResAssets.at(file, width: Int, height: Int)
# Fixed image scaling
GET /res/small/:file se.digiplant.scalr.ScalrResAssets.at(file, width: Int = 50, height: Int = 50)
GET /res/medium/:file se.digiplant.scalr.ScalrResAssets.at(file, width: Int = 200, height: Int = 200)
# Image resizing for any folder specified as path parameter (will cache thumbnails using play-res plugin)
GET /scalr/:width/:height/*file se.digiplant.scalr.ScalrAssets.at(path="/public/images", file, width: Int, height: Int)
The play-res plugin generates a unique sha1 hash of the file and stores the file on disk in an optimal 4char/4char/sha1hash.ext
directory structure.
By only having to save the fileuid (5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg) to the db it's easy to retrieve the image or other document (see play-res documentation)
<img src="@scalr.routes.ScalrResAssets.at("5564ac5e3968e77b4022f55a23d36630bdeb0274.jpg", 150, 100)" alt="" />
Will take the image /public/images/test/myimage.jpg
and resize it to 150, 100 and store it in res/scalr/test/myimage_150x100.jpg
and return the url as specified in the routes file.
<img src="@scalr.routes.ScalrAssets.at("test/myimage.jpg", 150, 100)" alt="" />
By specifying a mode you can fit the image within the bounding box in different ways.
// Specify one of automatic, fit_exact, fit_to_width, fit_to_height, default is automatic
scalr.routes.ScalrAssets.at("test/myimage.jpg", 150, 100, "fit_to_height")
You can specify multiple sources if you would like to split you images into categories, such as profile images / uploads.
By then adding another source in conf/application.conf
res.profile=res/profile
you will also have to add another route
GET /profile/:width/:height/:file se.digiplant.scalr.ScalrResAssets.at(source="profile", file, width: Int, height: Int)