diff --git a/src/main/java/lc/captchas/FontFunCaptcha.java b/src/main/java/lc/captchas/FontFunCaptcha.java index be09485..8dbea52 100644 --- a/src/main/java/lc/captchas/FontFunCaptcha.java +++ b/src/main/java/lc/captchas/FontFunCaptcha.java @@ -9,7 +9,7 @@ import java.util.Map; import java.util.List; import lc.captchas.interfaces.Challenge; import lc.captchas.interfaces.ChallengeProvider; -import lc.misc.DPISetter; +import lc.misc.PngImageWriter; import lc.misc.HelperFunctions; public class FontFunCaptcha implements ChallengeProvider { @@ -74,8 +74,7 @@ public class FontFunCaptcha implements ChallengeProvider { graphics2D.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - DPISetter dpi = new DPISetter(); - dpi.setDPI(baos, img); + PngImageWriter.write(baos, img); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/lc/captchas/ShadowTextCaptcha.java b/src/main/java/lc/captchas/ShadowTextCaptcha.java index 16f2b54..a797c50 100644 --- a/src/main/java/lc/captchas/ShadowTextCaptcha.java +++ b/src/main/java/lc/captchas/ShadowTextCaptcha.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.List; import lc.misc.HelperFunctions; -import lc.misc.DPISetter; +import lc.misc.PngImageWriter; import lc.captchas.interfaces.Challenge; import lc.captchas.interfaces.ChallengeProvider; @@ -67,8 +67,7 @@ public class ShadowTextCaptcha implements ChallengeProvider { g2d.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - DPISetter dpi = new DPISetter(); - dpi.setDPI(baos, img2); + PngImageWriter.write(baos, img2); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/lc/misc/DPISetter.java b/src/main/java/lc/misc/PngImageWriter.java similarity index 87% rename from src/main/java/lc/misc/DPISetter.java rename to src/main/java/lc/misc/PngImageWriter.java index 38b8c07..21b5034 100644 --- a/src/main/java/lc/misc/DPISetter.java +++ b/src/main/java/lc/misc/PngImageWriter.java @@ -15,12 +15,12 @@ import javax.imageio.metadata.IIOMetadataNode; import javax.imageio.stream.ImageOutputStream; import java.awt.image.BufferedImage; -public class DPISetter { +public class PngImageWriter { - final int DPI = 245; - final double INCH_2_CM = 2.54; + static final int DPI = 245; + static final double INCH_2_CM = 2.54; - public void setDPI(ByteArrayOutputStream boas, BufferedImage gridImage) throws IOException { + public static void write(ByteArrayOutputStream boas, BufferedImage gridImage) throws IOException { final String formatName = "png"; for (Iterator iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext(); ) { @@ -45,7 +45,7 @@ public class DPISetter { } } - public void setDPIMeta(IIOMetadata metadata) throws IIOInvalidTreeException { + private static void setDPIMeta(IIOMetadata metadata) throws IIOInvalidTreeException { // for PNG, it's dots per millimeter double dotsPerMilli = 1.0 * DPI / 10 / INCH_2_CM; diff --git a/src/main/scala/lc/captchas/DebugCaptcha.scala b/src/main/scala/lc/captchas/DebugCaptcha.scala index 5a0f0f1..f0add52 100644 --- a/src/main/scala/lc/captchas/DebugCaptcha.scala +++ b/src/main/scala/lc/captchas/DebugCaptcha.scala @@ -11,7 +11,7 @@ import java.util.List import lc.misc.HelperFunctions import lc.captchas.interfaces.Challenge import lc.captchas.interfaces.ChallengeProvider -import lc.misc.DPISetter +import lc.misc.PngImageWriter /** This captcha is only for debugging purposes. It creates very simple captchas that are deliberately easy to solve with OCR engines */ class DebugCaptcha extends ChallengeProvider { @@ -53,8 +53,7 @@ class DebugCaptcha extends ChallengeProvider { graphics2D.dispose() val baos = new ByteArrayOutputStream() try { - val dpi = new DPISetter(); - dpi.setDPI(baos, img); + PngImageWriter.write(baos, img); } catch { case e: Exception => e.printStackTrace() diff --git a/src/main/scala/lc/captchas/LabelCaptcha.scala b/src/main/scala/lc/captchas/LabelCaptcha.scala index 7b85e06..18048f8 100644 --- a/src/main/scala/lc/captchas/LabelCaptcha.scala +++ b/src/main/scala/lc/captchas/LabelCaptcha.scala @@ -10,7 +10,7 @@ import java.awt.Color import lc.captchas.interfaces.ChallengeProvider import lc.captchas.interfaces.Challenge import java.util.{List => JavaList, Map => JavaMap} -import lc.misc.DPISetter +import lc.misc.PngImageWriter class LabelCaptcha extends ChallengeProvider { private var knownFiles = new File("known").list.toList @@ -50,8 +50,7 @@ class LabelCaptcha extends ChallengeProvider { val token = encrypt(knownImageFile + "," + unknownImageFile) val baos = new ByteArrayOutputStream() - val dpi = new DPISetter(); - dpi.setDPI(baos, mergedImage); + PngImageWriter.write(baos, mergedImage); new Challenge(baos.toByteArray(), "image/png", token) }