Last active
June 12, 2018 13:07
-
-
Save duanebester/cdec9ce516a85414f9d6beedf327b655 to your computer and use it in GitHub Desktop.
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
def imageDeSkew(skewThreshold:Double = 0.05) = Flow[BufferedImage].map(bi => { | |
val deSkew = new ImageDeskew(bi) | |
val imageSkewAngle = deSkew.getSkewAngle | |
if (imageSkewAngle > skewThreshold || imageSkewAngle < -skewThreshold) { | |
ImageUtil.rotate(bi, -imageSkewAngle, bi.getWidth() / 2, bi.getHeight() / 2) | |
} else { | |
bi | |
} | |
}) | |
def imageWriter(format:String = "png") = Flow[BufferedImage].map(bi => { | |
val ri = bi.asInstanceOf[RenderedImage] | |
val outPutStream = new ByteArrayOutputStream | |
val writer = ImageIO.getImageWritersByFormatName(format).next() | |
val imageOutputStream = ImageIO.createImageOutputStream(outPutStream) | |
writer.setOutput(imageOutputStream) | |
writer.write(ri) | |
val bytes = outPutStream.toByteArray | |
outPutStream.close() | |
ByteString(bytes) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment