Created
January 16, 2012 15:29
-
-
Save osima/1621382 to your computer and use it in GitHub Desktop.
resize all png images in current dir.
This file contains 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 java.awt.Image | |
import java.awt.image.BufferedImage | |
import javax.imageio.ImageIO | |
class Conv { | |
File inputFile | |
File outputFile | |
void proc(){ | |
int width=500 // default width | |
// イメージの読み込みとリサイズ | |
def img = ImageIO.read(inputFile) | |
def imgScaled = img.getScaledInstance(width,-1,Image.SCALE_SMOOTH) | |
// リサイズ(スケール)されたイメージを直接 ImageIO.write() できないので、処理を追加 | |
def img2 = new BufferedImage((int)imgScaled.width,(int)imgScaled.height,BufferedImage.TYPE_4BYTE_ABGR) | |
def g = img2.getGraphics(); | |
g.drawImage(imgScaled,0,0,null) | |
g.dispose() | |
// リサイズされたイメージを保存 | |
ImageIO.write(img2,'PNG',outputFile) | |
} | |
} | |
new File('.').listFiles( { it.isFile() && it.name.endsWith('png') } as FileFilter ).each{ | |
new Conv( inputFile:it,outputFile:it ).proc() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment