Skip to content

Instantly share code, notes, and snippets.

@jericks
Created November 17, 2014 03:32
Show Gist options
  • Save jericks/fce52336bb9132ca084f to your computer and use it in GitHub Desktop.
Save jericks/fce52336bb9132ca084f to your computer and use it in GitHub Desktop.
import javax.imageio.ImageIO
import java.awt.*
import java.awt.image.*
if (args.length < 2) {
println "Usage: groovy tabs.groovy input.png output.png"
System.exit(-1)
}
String inputFile = args[0]
String outputFile = args[1]
def drawTab(Graphics2D g, x, y, side) {
// top
if (side.equalsIgnoreCase("top")) {
g.drawLine(x, y, x+20, y-20)
g.drawLine(x + 20, y - 20, x + 300 - 20, y - 20)
g.drawLine(x + 300, y, x + 300 - 20, y - 20)
}
// bottom
else if (side.equalsIgnoreCase("bottom")) {
g.drawLine(x, y, x+20, y+20)
g.drawLine(x + 20, y + 20, x + 300 - 20, y + 20)
g.drawLine(x + 300, y, x + 300 - 20, y + 20)
}
// east
else if (side.equalsIgnoreCase("east")) {
g.drawLine(x, y, x + 20, y + 20)
g.drawLine(x + 20, y + 20, x + 20, y + 300 - 20)
g.drawLine(x, y + 300, x + 20, y + 300 - 20)
}
}
def image1 = ImageIO.read(new File(inputFile))
def image2 = new BufferedImage(1810,1200, BufferedImage.TYPE_INT_ARGB)
Graphics2D g = image2.createGraphics()
g.paint = new Color(255,255,255)
g.fillRect(0,0,1810,1200)
g.drawImage(image1, 0,150,null)
g.paint = new Color(0,0,0)
// top
drawTab(g, 304, 454, "top")
drawTab(g, 304 + 300, 454 - 300, "top")
drawTab(g, 304 + (300 * 2), 454, "top")
//drawTab(g, 304 + (300 * 3), 454, "top")
// bottom
drawTab(g, 304, 754, "bottom")
drawTab(g, 304 + (300 * 2), 754, "bottom")
drawTab(g, 304 + (300 * 3), 754, "bottom")
// east
drawTab(g, 304 + (300 * 4), 454, "east")
g.dispose()
ImageIO.write(image2, "PNG", new File(outputFile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment