@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 gr2 = img2.createGraphics() def padding = 10d gr2.setColor(new Color((int)0xffffffff)) def rr = new Rectangle2D.Double( padding, padding, img.getWidth()-padding*2, img.getHeight()-padding*2) gr2.fill(rr) gr2.dispose() def df = new DiffuseFilter() df.setScale((int)padding) img2 = df.filter(img2, null) def mf = new MedianFilter() img2 = mf.filter(img2, null) gr2 = img2.createGraphics() gr2.setComposite(AlphaComposite.SrcIn) gr2.drawImage(img,0,0,null) gr2.dispose() ImageIO.write(img2, "png", new File("handcut.png"))
元画像
出力画像
動作環境
groovy 1.8.6, JDK7 update4
No comments:
Post a Comment