mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-13 06:53:19 -05:00
Set DPI for captcha providers
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
d30249a89f
commit
26d86bca4c
@ -1,6 +1,5 @@
|
|||||||
package lc.captchas;
|
package lc.captchas;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -10,6 +9,7 @@ import java.util.Map;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lc.captchas.interfaces.Challenge;
|
import lc.captchas.interfaces.Challenge;
|
||||||
import lc.captchas.interfaces.ChallengeProvider;
|
import lc.captchas.interfaces.ChallengeProvider;
|
||||||
|
import lc.misc.DPISetter;
|
||||||
import lc.misc.HelperFunctions;
|
import lc.misc.HelperFunctions;
|
||||||
|
|
||||||
public class FontFunCaptcha implements ChallengeProvider {
|
public class FontFunCaptcha implements ChallengeProvider {
|
||||||
@ -74,7 +74,8 @@ public class FontFunCaptcha implements ChallengeProvider {
|
|||||||
graphics2D.dispose();
|
graphics2D.dispose();
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
ImageIO.write(img, "png", baos);
|
DPISetter dpi = new DPISetter();
|
||||||
|
dpi.setDPI(baos, img);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package lc.captchas;
|
package lc.captchas;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@ -14,6 +13,7 @@ import java.util.Map;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lc.misc.HelperFunctions;
|
import lc.misc.HelperFunctions;
|
||||||
|
import lc.misc.DPISetter;
|
||||||
import lc.captchas.interfaces.Challenge;
|
import lc.captchas.interfaces.Challenge;
|
||||||
import lc.captchas.interfaces.ChallengeProvider;
|
import lc.captchas.interfaces.ChallengeProvider;
|
||||||
|
|
||||||
@ -67,7 +67,8 @@ public class ShadowTextCaptcha implements ChallengeProvider {
|
|||||||
g2d.dispose();
|
g2d.dispose();
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
try {
|
||||||
ImageIO.write(img2, "png", baos);
|
DPISetter dpi = new DPISetter();
|
||||||
|
dpi.setDPI(baos, img2);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package lc.captchas
|
package lc.captchas
|
||||||
|
|
||||||
import javax.imageio.ImageIO
|
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
import java.awt.font.TextLayout
|
import java.awt.font.TextLayout
|
||||||
@ -12,6 +11,7 @@ import java.util.List
|
|||||||
import lc.misc.HelperFunctions
|
import lc.misc.HelperFunctions
|
||||||
import lc.captchas.interfaces.Challenge
|
import lc.captchas.interfaces.Challenge
|
||||||
import lc.captchas.interfaces.ChallengeProvider
|
import lc.captchas.interfaces.ChallengeProvider
|
||||||
|
import lc.misc.DPISetter
|
||||||
|
|
||||||
/** This captcha is only for debugging purposes. It creates very simple captchas that are deliberately easy to solve with OCR engines */
|
/** 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 {
|
class DebugCaptcha extends ChallengeProvider {
|
||||||
@ -53,7 +53,8 @@ class DebugCaptcha extends ChallengeProvider {
|
|||||||
graphics2D.dispose()
|
graphics2D.dispose()
|
||||||
val baos = new ByteArrayOutputStream()
|
val baos = new ByteArrayOutputStream()
|
||||||
try {
|
try {
|
||||||
ImageIO.write(img, "png", baos)
|
val dpi = new DPISetter();
|
||||||
|
dpi.setDPI(baos, img);
|
||||||
} catch {
|
} catch {
|
||||||
case e: Exception =>
|
case e: Exception =>
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
@ -10,6 +10,7 @@ import java.awt.Color
|
|||||||
import lc.captchas.interfaces.ChallengeProvider
|
import lc.captchas.interfaces.ChallengeProvider
|
||||||
import lc.captchas.interfaces.Challenge
|
import lc.captchas.interfaces.Challenge
|
||||||
import java.util.{List => JavaList, Map => JavaMap}
|
import java.util.{List => JavaList, Map => JavaMap}
|
||||||
|
import lc.misc.DPISetter
|
||||||
|
|
||||||
class LabelCaptcha extends ChallengeProvider {
|
class LabelCaptcha extends ChallengeProvider {
|
||||||
private var knownFiles = new File("known").list.toList
|
private var knownFiles = new File("known").list.toList
|
||||||
@ -49,7 +50,8 @@ class LabelCaptcha extends ChallengeProvider {
|
|||||||
|
|
||||||
val token = encrypt(knownImageFile + "," + unknownImageFile)
|
val token = encrypt(knownImageFile + "," + unknownImageFile)
|
||||||
val baos = new ByteArrayOutputStream()
|
val baos = new ByteArrayOutputStream()
|
||||||
ImageIO.write(mergedImage, "png", baos)
|
val dpi = new DPISetter();
|
||||||
|
dpi.setDPI(baos, mergedImage);
|
||||||
|
|
||||||
new Challenge(baos.toByteArray(), "image/png", token)
|
new Challenge(baos.toByteArray(), "image/png", token)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user