play-scalr


License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

se.digiplant
ArtifactId

ArtifactId

play-scalr_2.9.1
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

play-scalr
play-scalr
Project URL

Project URL

https://github.com/digiPlant/play-scalr
Project Organization

Project Organization

se.digiplant

Download play-scalr_2.9.1

How to add to project

<!-- https://jarcasting.com/artifacts/se.digiplant/play-scalr_2.9.1/ -->
<dependency>
    <groupId>se.digiplant</groupId>
    <artifactId>play-scalr_2.9.1</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/se.digiplant/play-scalr_2.9.1/
implementation 'se.digiplant:play-scalr_2.9.1:1.0'
// https://jarcasting.com/artifacts/se.digiplant/play-scalr_2.9.1/
implementation ("se.digiplant:play-scalr_2.9.1:1.0")
'se.digiplant:play-scalr_2.9.1:jar:1.0'
<dependency org="se.digiplant" name="play-scalr_2.9.1" rev="1.0">
  <artifact name="play-scalr_2.9.1" type="jar" />
</dependency>
@Grapes(
@Grab(group='se.digiplant', module='play-scalr_2.9.1', version='1.0')
)
libraryDependencies += "se.digiplant" % "play-scalr_2.9.1" % "1.0"
[se.digiplant/play-scalr_2.9.1 "1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.9.1
se.digiplant : play-res_2.9.1 jar 1.0

provided (1)

Group / Artifact Type Version
play » play_2.9.1 jar 2.0.4

test (1)

Group / Artifact Type Version
play » play-test_2.9.1 jar 2.0.4

Project Modules

There are no modules declared in this project.

Scalr plugin for Play Framework 2

Install

Add plugin to dependencies

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._"

Add to conf/application.conf

# 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

Add to conf/routes

# 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)

Usage

Reverse routing to the play-res plugin backed scalr resizer

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="" />

Reverse routing to a directory resizer

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="" />

Modes

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")

Advanced Usage

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)
se.digiplant

digiPlant

Versions

Version
1.0