@Grab(group='com.jhlabs', module='filters', version='2.0.235') import java.awt.* import java.awt.geom.* import java.awt.image.* import java.io.* import javax.imageio.* import com.jhlabs.composite.* import com.jhlabs.image.* // 画像を夢のように切り取る def img = ImageIO.read(new File("sf2.jpg")) // マスクを作成 def img2 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) def gr = img2.createGraphics() gr.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) gr.setColor(new Color(1F, 1F, 1F, 1F)) def rr = new RoundRectangle2D.Double( 0.0, 0.0, img.getWidth()-1, img.getHeight()-1, 20.0*2, 20.0*2) gr.fill(rr) gr.dispose() // 揺らす def wavelen = 10f def rf = new RippleFilter() rf.setXAmplitude((float)wavelen/2) rf.setXWavelength(wavelen) rf.setYAmplitude((float)wavelen/2) rf.setYWavelength(wavelen) img2 = rf.filter(img2, null) def img3 = new BufferedImage( (int)img2.getWidth()+wavelen, (int)img2.getHeight()+wavelen, BufferedImage.TYPE_INT_ARGB ) gr = img3.createGraphics() gr.drawImage(img2,(int)wavelen/2,(int)wavelen/2,null) gr.dispose() // リサイズ img2 = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB ) ScaleFilter sf = new ScaleFilter(img.getWidth(), img.getHeight()) img3 = sf.filter(img3, img2) // ぼかす def gf = new GaussianFilter() gf.setRadius(10f) img3 = gf.filter(img3, null) // 切り取り gr = img3.createGraphics() gr.setComposite(AlphaComposite.SrcIn) gr.drawImage(img,0,0,null) gr.dispose() ImageIO.write(img3, "png", new File("dreamy.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment