Skip to content

Instantly share code, notes, and snippets.

@dhoss
Created April 29, 2013 20:19
Show Gist options
  • Save dhoss/5484465 to your computer and use it in GitHub Desktop.
Save dhoss/5484465 to your computer and use it in GitHub Desktop.
error: play test [info] Loading project definition from /Users/daustin/web-dev/lumos-pottery/project [info] Set current project to lumos (in build file:/Users/daustin/web-dev/lumos-pottery/) [info] Compiling 10 Scala sources and 1 Java source to /Users/daustin/web-dev/lumos-pottery/target/scala-2.10/classes... [error] /Users/daustin/web-dev/lumo…
/** GenerateThumbnail
* generate a thumbnail of an image
*
* ==Overview==
* {{{
* val thumbnail = new Thumbnailer(.25, "image.jpg", "image-thumbnail.jpg")
* val resized = thumbnail.resize()
* thumbnail.save()
* }}}
*/
package app.thumbnailer
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
import java.io._
import net.coobird.thumbnailator._
/** Generate a thumbnail */
class Thumbnailer( scale: Double, file: String, outputPath: String ) {
/** Resize an image and return the data
* @param scale percent to scale image by
* @param file original file to be thumbnailed
*/
var scaled_thumbnail_data = null
def resize {
scaled_thumbnail_data = Thumbnails.of(file).scale(scale)
}
def save {
scaled_thumbnail_data.outputFormat("png").toFile(new File(outputPath))
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test
import org.scalatest.FunSpec
import app.thumbnailer._
import javax.imageio.ImageIO
import scala.io.Source
class ThumbnailSpec extends FunSpec {
val test_image = Source.fromURL(getClass.getResource("/test.jpg"))
describe("A Thumbnail") {
it("should resize to a proper scale") {
val thumbnailer = new Thumbnailer(0.25, test_image.mkString(), "./test-thumbnail.jpg")
val thumbnail = thumbnailer.resize()
val thumb_height = thumbnail.thumbnail_data.getHeight()
val thumb_width = thumbnail.thumbnail_data.getWidth()
val original_image_height = test_image.getHeight()
val original_image_width = test_image.getWidth()
assert(thumb_height === original_image_height*.25)
assert(thumb_width === original_image_width*.25)
}
it("should throw FileNotFoundException if the original file does not exist") (pending)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment