Last active
April 12, 2016 19:31
-
-
Save brooksandrew/7f123b4acb3dcf52ecb9951858974efb to your computer and use it in GitHub Desktop.
Re-size images using ImageIO and imgscalr in Scala and save output as a new jpgs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.imgscalr._ | |
import java.io.File | |
import javax.imageio.ImageIO | |
object resize extends App { | |
def resizeImg(img: java.awt.image.BufferedImage, width: Int, height: Int) = { | |
Scalr.resize(img, Scalr.Method.BALANCED, width, height) | |
} | |
val myimg = ImageIO.read(new File("20square.jpg")) | |
val myimg32 = resizeImg(myimg, 32, 32) | |
val myimg64 = resizeImg(myimg, 64, 64) | |
val myimg128 = resizeImg(myimg, 128, 128) | |
val myimg256 = resizeImg(myimg, 256, 256) | |
ImageIO.write(myimg32, "jpg", new File("20resize32.jpg")) | |
ImageIO.write(myimg64, "jpg", new File("20resize64.jpg")) | |
ImageIO.write(myimg128, "jpg", new File("20resize128.jpg")) | |
ImageIO.write(myimg256, "jpg", new File("20resize256.jpg")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment