Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala image resize and crop [closed]

I have a Play framework 2.2 app and I want to resize and crop images (like profile picture). Is there a good Scala library that I can use to do this? And if not which Java library should I use (considering performance, quality...). An example would be appreciated.

like image 962
ameernuri Avatar asked Nov 16 '13 07:11

ameernuri


2 Answers

I've used Thumbnaiator https://code.google.com/p/thumbnailator/ in Java before. Works really well and is pure Java so doesn't require any native dependencies.

like image 102
Jason Avatar answered Sep 19 '22 03:09

Jason


If you just need to resize images, you don't need any addition library/dependencies. Just use the Java BufferedImage class so be enough.

// Target size
val width = 100
val height = 100

// Load image from disk
val originalImage: BufferedImage = ImageIO.read(new File("test-data/test.jpg"))

// Resize
val resized = originalImage.getScaledInstance(width, height, Image.SCALE_DEFAULT)

// Saving Image back to disck
val bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
bufferedImage.getGraphics.drawImage(resized, 0, 0, null)
ImageIO.write(bufferedImage, "JPEG", new File("test-data/resized.jpg"))

You'll need these imports:

import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
like image 27
Yuchen Avatar answered Sep 20 '22 03:09

Yuchen