mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-11-26 04:26:05 -05:00
Linter and Formatter support (#58)
* Add scala linter and formatter Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com> * Add java formatter Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com> * Add linter support Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com> * Increase maxColumn limit Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com> * Reformat and lint Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com> * Minor reformatting Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com> * Add scala formatter on compile option Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com> * Enable scala linter for CI Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6d04cdc3b4
commit
de50d8123e
@@ -10,69 +10,71 @@ import lc.captchas.interfaces.Challenge;
|
||||
import lc.captchas.interfaces.ChallengeProvider;
|
||||
import lc.misc.HelperFunctions;
|
||||
|
||||
public class FontFunCaptcha implements ChallengeProvider{
|
||||
public class FontFunCaptcha implements ChallengeProvider {
|
||||
|
||||
public String getId() {
|
||||
return "FontFunCaptcha";
|
||||
}
|
||||
public String getId() {
|
||||
return "FontFunCaptcha";
|
||||
}
|
||||
|
||||
private String getFontName(String path, String level){
|
||||
File file = new File(path+level+"/");
|
||||
FilenameFilter txtFileFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name)
|
||||
{
|
||||
if(name.endsWith(".ttf"))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
private String getFontName(String path, String level) {
|
||||
File file = new File(path + level + "/");
|
||||
FilenameFilter txtFileFilter =
|
||||
new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.endsWith(".ttf")) return true;
|
||||
else return false;
|
||||
}
|
||||
};
|
||||
File[] files = file.listFiles(txtFileFilter);
|
||||
return path+level.toLowerCase()+"/"+files[HelperFunctions.randomNumber(0,files.length-1)].getName();
|
||||
}
|
||||
File[] files = file.listFiles(txtFileFilter);
|
||||
return path
|
||||
+ level.toLowerCase()
|
||||
+ "/"
|
||||
+ files[HelperFunctions.randomNumber(0, files.length - 1)].getName();
|
||||
}
|
||||
|
||||
private Font loadCustomFont(String level, String path) {
|
||||
String fontName = getFontName(path,level);
|
||||
try{
|
||||
Font font = Font.createFont(Font.TRUETYPE_FONT, new File(fontName));
|
||||
font = font.deriveFont(Font.PLAIN, 48f);
|
||||
return font;
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
private Font loadCustomFont(String level, String path) {
|
||||
String fontName = getFontName(path, level);
|
||||
try {
|
||||
Font font = Font.createFont(Font.TRUETYPE_FONT, new File(fontName));
|
||||
font = font.deriveFont(Font.PLAIN, 48f);
|
||||
return font;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private byte[] fontFun(String captchaText, String level, String path){
|
||||
String[] colors = {"#f68787","#f8a978","#f1eb9a","#a4f6a5"};
|
||||
BufferedImage img = new BufferedImage(350, 100, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics2D = img.createGraphics();
|
||||
for(int i=0; i< captchaText.length(); i++) {
|
||||
Font font = loadCustomFont(level,path);
|
||||
graphics2D.setFont(font);
|
||||
FontMetrics fontMetrics = graphics2D.getFontMetrics();
|
||||
HelperFunctions.setRenderingHints(graphics2D);
|
||||
graphics2D.setColor(Color.decode(colors[HelperFunctions.randomNumber(0,3)]));
|
||||
graphics2D.drawString(String.valueOf(captchaText.charAt(i)), (i * 48), fontMetrics.getAscent());
|
||||
}
|
||||
graphics2D.dispose();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(img,"png",baos);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
private byte[] fontFun(String captchaText, String level, String path) {
|
||||
String[] colors = {"#f68787", "#f8a978", "#f1eb9a", "#a4f6a5"};
|
||||
BufferedImage img = new BufferedImage(350, 100, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics2D = img.createGraphics();
|
||||
for (int i = 0; i < captchaText.length(); i++) {
|
||||
Font font = loadCustomFont(level, path);
|
||||
graphics2D.setFont(font);
|
||||
FontMetrics fontMetrics = graphics2D.getFontMetrics();
|
||||
HelperFunctions.setRenderingHints(graphics2D);
|
||||
graphics2D.setColor(Color.decode(colors[HelperFunctions.randomNumber(0, 3)]));
|
||||
graphics2D.drawString(
|
||||
String.valueOf(captchaText.charAt(i)), (i * 48), fontMetrics.getAscent());
|
||||
}
|
||||
graphics2D.dispose();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(img, "png", baos);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public Challenge returnChallenge() {
|
||||
String secret = HelperFunctions.randomString(7);
|
||||
String path = "./lib/fonts/";
|
||||
return new Challenge(fontFun(secret,"medium",path),"image/png",secret.toLowerCase());
|
||||
}
|
||||
public Challenge returnChallenge() {
|
||||
String secret = HelperFunctions.randomString(7);
|
||||
String path = "./lib/fonts/";
|
||||
return new Challenge(fontFun(secret, "medium", path), "image/png", secret.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean checkAnswer(String secret, String answer){
|
||||
return answer.toLowerCase().equals(secret);
|
||||
}
|
||||
public boolean checkAnswer(String secret, String answer) {
|
||||
return answer.toLowerCase().equals(secret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,49 +14,50 @@ import lc.captchas.interfaces.ChallengeProvider;
|
||||
import lc.misc.HelperFunctions;
|
||||
import lc.misc.GifSequenceWriter;
|
||||
|
||||
public class GifCaptcha implements ChallengeProvider{
|
||||
public class GifCaptcha implements ChallengeProvider {
|
||||
|
||||
private BufferedImage charToImg(String text){
|
||||
BufferedImage img = new BufferedImage(250, 100, BufferedImage.TYPE_INT_RGB);
|
||||
Font font = new Font("Bradley Hand", Font.ROMAN_BASELINE, 48);
|
||||
Graphics2D graphics2D = img.createGraphics();
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
graphics2D.setFont(font);
|
||||
graphics2D.setColor(new Color((int)(Math.random() * 0x1000000)));
|
||||
graphics2D.drawString( text , 45, 45);
|
||||
graphics2D.dispose();
|
||||
return img;
|
||||
}
|
||||
private BufferedImage charToImg(String text) {
|
||||
BufferedImage img = new BufferedImage(250, 100, BufferedImage.TYPE_INT_RGB);
|
||||
Font font = new Font("Bradley Hand", Font.ROMAN_BASELINE, 48);
|
||||
Graphics2D graphics2D = img.createGraphics();
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics2D.setRenderingHint(
|
||||
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
graphics2D.setFont(font);
|
||||
graphics2D.setColor(new Color((int) (Math.random() * 0x1000000)));
|
||||
graphics2D.drawString(text, 45, 45);
|
||||
graphics2D.dispose();
|
||||
return img;
|
||||
}
|
||||
|
||||
private byte[] gifCaptcha(String text){
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
ImageOutputStream output = new MemoryCacheImageOutputStream(byteArrayOutputStream);
|
||||
GifSequenceWriter writer = new GifSequenceWriter( output, 1,1000, true );
|
||||
for(int i=0; i< text.length(); i++){
|
||||
BufferedImage nextImage = charToImg(String.valueOf(text.charAt(i)));
|
||||
writer.writeToSequence(nextImage);
|
||||
}
|
||||
writer.close();
|
||||
output.close();
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
private byte[] gifCaptcha(String text) {
|
||||
try {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
ImageOutputStream output = new MemoryCacheImageOutputStream(byteArrayOutputStream);
|
||||
GifSequenceWriter writer = new GifSequenceWriter(output, 1, 1000, true);
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
BufferedImage nextImage = charToImg(String.valueOf(text.charAt(i)));
|
||||
writer.writeToSequence(nextImage);
|
||||
}
|
||||
writer.close();
|
||||
output.close();
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Challenge returnChallenge() {
|
||||
String secret = HelperFunctions.randomString(6);
|
||||
return new Challenge(gifCaptcha(secret),"image/gif",secret.toLowerCase());
|
||||
}
|
||||
public Challenge returnChallenge() {
|
||||
String secret = HelperFunctions.randomString(6);
|
||||
return new Challenge(gifCaptcha(secret), "image/gif", secret.toLowerCase());
|
||||
}
|
||||
|
||||
public boolean checkAnswer(String secret, String answer) {
|
||||
return answer.toLowerCase().equals(secret);
|
||||
}
|
||||
public boolean checkAnswer(String secret, String answer) {
|
||||
return answer.toLowerCase().equals(secret);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return "GifCaptcha";
|
||||
}
|
||||
public String getId() {
|
||||
return "GifCaptcha";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,54 +14,54 @@ import lc.misc.HelperFunctions;
|
||||
import lc.captchas.interfaces.Challenge;
|
||||
import lc.captchas.interfaces.ChallengeProvider;
|
||||
|
||||
public class ShadowTextCaptcha implements ChallengeProvider{
|
||||
public class ShadowTextCaptcha implements ChallengeProvider {
|
||||
|
||||
public String getId() {
|
||||
return "ShadowTextCaptcha";
|
||||
public String getId() {
|
||||
return "ShadowTextCaptcha";
|
||||
}
|
||||
|
||||
public boolean checkAnswer(String secret, String answer) {
|
||||
return answer.toLowerCase().equals(secret);
|
||||
}
|
||||
|
||||
private byte[] shadowText(String text) {
|
||||
BufferedImage img = new BufferedImage(350, 100, BufferedImage.TYPE_INT_RGB);
|
||||
Font font = new Font("Arial", Font.ROMAN_BASELINE, 48);
|
||||
Graphics2D graphics2D = img.createGraphics();
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics2D.setRenderingHint(
|
||||
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
TextLayout textLayout = new TextLayout(text, font, graphics2D.getFontRenderContext());
|
||||
HelperFunctions.setRenderingHints(graphics2D);
|
||||
graphics2D.setPaint(Color.WHITE);
|
||||
graphics2D.fillRect(0, 0, 350, 100);
|
||||
graphics2D.setPaint(Color.BLACK);
|
||||
textLayout.draw(graphics2D, 15, 50);
|
||||
graphics2D.dispose();
|
||||
float[] kernel = {
|
||||
1f / 9f, 1f / 9f, 1f / 9f,
|
||||
1f / 9f, 1f / 9f, 1f / 9f,
|
||||
1f / 9f, 1f / 9f, 1f / 9f
|
||||
};
|
||||
ConvolveOp op = new ConvolveOp(new Kernel(3, 3, kernel), ConvolveOp.EDGE_NO_OP, null);
|
||||
BufferedImage img2 = op.filter(img, null);
|
||||
Graphics2D g2d = img2.createGraphics();
|
||||
HelperFunctions.setRenderingHints(g2d);
|
||||
g2d.setPaint(Color.WHITE);
|
||||
textLayout.draw(g2d, 13, 50);
|
||||
g2d.dispose();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(img2, "png", baos);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public boolean checkAnswer(String secret, String answer) {
|
||||
return answer.toLowerCase().equals(secret);
|
||||
}
|
||||
|
||||
private byte[] shadowText(String text){
|
||||
BufferedImage img = new BufferedImage(350, 100, BufferedImage.TYPE_INT_RGB);
|
||||
Font font = new Font("Arial",Font.ROMAN_BASELINE ,48);
|
||||
Graphics2D graphics2D = img.createGraphics();
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
TextLayout textLayout = new TextLayout(text, font, graphics2D.getFontRenderContext());
|
||||
HelperFunctions.setRenderingHints(graphics2D);
|
||||
graphics2D.setPaint(Color.WHITE);
|
||||
graphics2D.fillRect(0, 0, 350, 100);
|
||||
graphics2D.setPaint(Color.BLACK);
|
||||
textLayout.draw(graphics2D, 15, 50);
|
||||
graphics2D.dispose();
|
||||
float[] kernel = {
|
||||
1f / 9f, 1f / 9f, 1f / 9f,
|
||||
1f / 9f, 1f / 9f, 1f / 9f,
|
||||
1f / 9f, 1f / 9f, 1f / 9f
|
||||
};
|
||||
ConvolveOp op = new ConvolveOp(new Kernel(3, 3, kernel),
|
||||
ConvolveOp.EDGE_NO_OP, null);
|
||||
BufferedImage img2 = op.filter(img, null);
|
||||
Graphics2D g2d = img2.createGraphics();
|
||||
HelperFunctions.setRenderingHints(g2d);
|
||||
g2d.setPaint(Color.WHITE);
|
||||
textLayout.draw(g2d, 13, 50);
|
||||
g2d.dispose();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
ImageIO.write(img2,"png",baos);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
public Challenge returnChallenge() {
|
||||
String secret = HelperFunctions.randomString(6);
|
||||
return new Challenge(shadowText(secret),"image/png",secret.toLowerCase());
|
||||
}
|
||||
public Challenge returnChallenge() {
|
||||
String secret = HelperFunctions.randomString(6);
|
||||
return new Challenge(shadowText(secret), "image/png", secret.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package lc.captchas.interfaces;
|
||||
|
||||
public interface ChallengeProvider {
|
||||
public String getId();
|
||||
|
||||
public Challenge returnChallenge();
|
||||
|
||||
public boolean checkAnswer(String secret, String answer);
|
||||
|
||||
//TODO: def configure(): Unit
|
||||
// TODO: def configure(): Unit
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// It was available under CC By 3.0
|
||||
|
||||
package lc.misc;
|
||||
|
||||
import javax.imageio.*;
|
||||
import javax.imageio.metadata.*;
|
||||
import javax.imageio.stream.*;
|
||||
@@ -10,136 +11,113 @@ import java.io.*;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GifSequenceWriter {
|
||||
protected ImageWriter gifWriter;
|
||||
protected ImageWriteParam imageWriteParam;
|
||||
protected IIOMetadata imageMetaData;
|
||||
protected ImageWriter gifWriter;
|
||||
protected ImageWriteParam imageWriteParam;
|
||||
protected IIOMetadata imageMetaData;
|
||||
|
||||
/**
|
||||
* Creates a new GifSequenceWriter
|
||||
*
|
||||
* @param outputStream the ImageOutputStream to be written to
|
||||
* @param imageType one of the imageTypes specified in BufferedImage
|
||||
* @param timeBetweenFramesMS the time between frames in miliseconds
|
||||
* @param loopContinuously wether the gif should loop repeatedly
|
||||
* @throws IIOException if no gif ImageWriters are found
|
||||
*
|
||||
* @author Elliot Kroo (elliot[at]kroo[dot]net)
|
||||
*/
|
||||
public GifSequenceWriter(
|
||||
ImageOutputStream outputStream,
|
||||
int imageType,
|
||||
int timeBetweenFramesMS,
|
||||
boolean loopContinuously) throws IIOException, IOException {
|
||||
// my method to create a writer
|
||||
gifWriter = getWriter();
|
||||
imageWriteParam = gifWriter.getDefaultWriteParam();
|
||||
ImageTypeSpecifier imageTypeSpecifier =
|
||||
ImageTypeSpecifier.createFromBufferedImageType(imageType);
|
||||
/**
|
||||
* Creates a new GifSequenceWriter
|
||||
*
|
||||
* @param outputStream the ImageOutputStream to be written to
|
||||
* @param imageType one of the imageTypes specified in BufferedImage
|
||||
* @param timeBetweenFramesMS the time between frames in miliseconds
|
||||
* @param loopContinuously wether the gif should loop repeatedly
|
||||
* @throws IIOException if no gif ImageWriters are found
|
||||
* @author Elliot Kroo (elliot[at]kroo[dot]net)
|
||||
*/
|
||||
public GifSequenceWriter(
|
||||
ImageOutputStream outputStream,
|
||||
int imageType,
|
||||
int timeBetweenFramesMS,
|
||||
boolean loopContinuously)
|
||||
throws IIOException, IOException {
|
||||
// my method to create a writer
|
||||
gifWriter = getWriter();
|
||||
imageWriteParam = gifWriter.getDefaultWriteParam();
|
||||
ImageTypeSpecifier imageTypeSpecifier =
|
||||
ImageTypeSpecifier.createFromBufferedImageType(imageType);
|
||||
|
||||
imageMetaData =
|
||||
gifWriter.getDefaultImageMetadata(imageTypeSpecifier,
|
||||
imageWriteParam);
|
||||
imageMetaData = gifWriter.getDefaultImageMetadata(imageTypeSpecifier, imageWriteParam);
|
||||
|
||||
String metaFormatName = imageMetaData.getNativeMetadataFormatName();
|
||||
String metaFormatName = imageMetaData.getNativeMetadataFormatName();
|
||||
|
||||
IIOMetadataNode root = (IIOMetadataNode)
|
||||
imageMetaData.getAsTree(metaFormatName);
|
||||
IIOMetadataNode root = (IIOMetadataNode) imageMetaData.getAsTree(metaFormatName);
|
||||
|
||||
IIOMetadataNode graphicsControlExtensionNode = getNode(
|
||||
root,
|
||||
"GraphicControlExtension");
|
||||
IIOMetadataNode graphicsControlExtensionNode = getNode(root, "GraphicControlExtension");
|
||||
|
||||
graphicsControlExtensionNode.setAttribute("disposalMethod", "none");
|
||||
graphicsControlExtensionNode.setAttribute("userInputFlag", "FALSE");
|
||||
graphicsControlExtensionNode.setAttribute(
|
||||
"transparentColorFlag",
|
||||
"FALSE");
|
||||
graphicsControlExtensionNode.setAttribute(
|
||||
"delayTime",
|
||||
Integer.toString(timeBetweenFramesMS / 10));
|
||||
graphicsControlExtensionNode.setAttribute(
|
||||
"transparentColorIndex",
|
||||
"0");
|
||||
graphicsControlExtensionNode.setAttribute("disposalMethod", "none");
|
||||
graphicsControlExtensionNode.setAttribute("userInputFlag", "FALSE");
|
||||
graphicsControlExtensionNode.setAttribute("transparentColorFlag", "FALSE");
|
||||
graphicsControlExtensionNode.setAttribute(
|
||||
"delayTime", Integer.toString(timeBetweenFramesMS / 10));
|
||||
graphicsControlExtensionNode.setAttribute("transparentColorIndex", "0");
|
||||
|
||||
IIOMetadataNode commentsNode = getNode(root, "CommentExtensions");
|
||||
commentsNode.setAttribute("CommentExtension", "Created by MAH");
|
||||
IIOMetadataNode commentsNode = getNode(root, "CommentExtensions");
|
||||
commentsNode.setAttribute("CommentExtension", "Created by MAH");
|
||||
|
||||
IIOMetadataNode appEntensionsNode = getNode(
|
||||
root,
|
||||
"ApplicationExtensions");
|
||||
IIOMetadataNode appEntensionsNode = getNode(root, "ApplicationExtensions");
|
||||
|
||||
IIOMetadataNode child = new IIOMetadataNode("ApplicationExtension");
|
||||
IIOMetadataNode child = new IIOMetadataNode("ApplicationExtension");
|
||||
|
||||
child.setAttribute("applicationID", "NETSCAPE");
|
||||
child.setAttribute("authenticationCode", "2.0");
|
||||
child.setAttribute("applicationID", "NETSCAPE");
|
||||
child.setAttribute("authenticationCode", "2.0");
|
||||
|
||||
int loop = loopContinuously ? 0 : 1;
|
||||
int loop = loopContinuously ? 0 : 1;
|
||||
|
||||
child.setUserObject(new byte[]{ 0x1, (byte) (loop & 0xFF), (byte)
|
||||
((loop >> 8) & 0xFF)});
|
||||
appEntensionsNode.appendChild(child);
|
||||
child.setUserObject(new byte[] {0x1, (byte) (loop & 0xFF), (byte) ((loop >> 8) & 0xFF)});
|
||||
appEntensionsNode.appendChild(child);
|
||||
|
||||
imageMetaData.setFromTree(metaFormatName, root);
|
||||
imageMetaData.setFromTree(metaFormatName, root);
|
||||
|
||||
gifWriter.setOutput(outputStream);
|
||||
gifWriter.setOutput(outputStream);
|
||||
|
||||
gifWriter.prepareWriteSequence(null);
|
||||
gifWriter.prepareWriteSequence(null);
|
||||
}
|
||||
|
||||
public void writeToSequence(RenderedImage img) throws IOException {
|
||||
gifWriter.writeToSequence(new IIOImage(img, null, imageMetaData), imageWriteParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close this GifSequenceWriter object. This does not close the underlying stream, just finishes
|
||||
* off the GIF.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
gifWriter.endWriteSequence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first available GIF ImageWriter using ImageIO.getImageWritersBySuffix("gif").
|
||||
*
|
||||
* @return a GIF ImageWriter object
|
||||
* @throws IIOException if no GIF image writers are returned
|
||||
*/
|
||||
private static ImageWriter getWriter() throws IIOException {
|
||||
Iterator<ImageWriter> iter = ImageIO.getImageWritersBySuffix("gif");
|
||||
if (!iter.hasNext()) {
|
||||
throw new IIOException("No GIF Image Writers Exist");
|
||||
} else {
|
||||
return iter.next();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToSequence(RenderedImage img) throws IOException {
|
||||
gifWriter.writeToSequence(
|
||||
new IIOImage(
|
||||
img,
|
||||
null,
|
||||
imageMetaData),
|
||||
imageWriteParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close this GifSequenceWriter object. This does not close the underlying
|
||||
* stream, just finishes off the GIF.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
gifWriter.endWriteSequence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first available GIF ImageWriter using
|
||||
* ImageIO.getImageWritersBySuffix("gif").
|
||||
*
|
||||
* @return a GIF ImageWriter object
|
||||
* @throws IIOException if no GIF image writers are returned
|
||||
*/
|
||||
private static ImageWriter getWriter() throws IIOException {
|
||||
Iterator<ImageWriter> iter = ImageIO.getImageWritersBySuffix("gif");
|
||||
if(!iter.hasNext()) {
|
||||
throw new IIOException("No GIF Image Writers Exist");
|
||||
} else {
|
||||
return iter.next();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an existing child node, or creates and returns a new child node (if
|
||||
* the requested node does not exist).
|
||||
*
|
||||
* @param rootNode the <tt>IIOMetadataNode</tt> to search for the child node.
|
||||
* @param nodeName the name of the child node.
|
||||
*
|
||||
* @return the child node, if found or a new node created with the given name.
|
||||
*/
|
||||
private static IIOMetadataNode getNode(
|
||||
IIOMetadataNode rootNode,
|
||||
String nodeName) {
|
||||
int nNodes = rootNode.getLength();
|
||||
for (int i = 0; i < nNodes; i++) {
|
||||
if (rootNode.item(i).getNodeName().compareToIgnoreCase(nodeName)
|
||||
== 0) {
|
||||
return((IIOMetadataNode) rootNode.item(i));
|
||||
}
|
||||
}
|
||||
IIOMetadataNode node = new IIOMetadataNode(nodeName);
|
||||
rootNode.appendChild(node);
|
||||
return(node);
|
||||
/**
|
||||
* Returns an existing child node, or creates and returns a new child node (if the requested node
|
||||
* does not exist).
|
||||
*
|
||||
* @param rootNode the <tt>IIOMetadataNode</tt> to search for the child node.
|
||||
* @param nodeName the name of the child node.
|
||||
* @return the child node, if found or a new node created with the given name.
|
||||
*/
|
||||
private static IIOMetadataNode getNode(IIOMetadataNode rootNode, String nodeName) {
|
||||
int nNodes = rootNode.getLength();
|
||||
for (int i = 0; i < nNodes; i++) {
|
||||
if (rootNode.item(i).getNodeName().compareToIgnoreCase(nodeName) == 0) {
|
||||
return ((IIOMetadataNode) rootNode.item(i));
|
||||
}
|
||||
}
|
||||
IIOMetadataNode node = new IIOMetadataNode(nodeName);
|
||||
rootNode.appendChild(node);
|
||||
return (node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,24 +4,24 @@ import java.awt.*;
|
||||
|
||||
public class HelperFunctions {
|
||||
|
||||
public static void setRenderingHints(Graphics2D g2d){
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
|
||||
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||
}
|
||||
public static void setRenderingHints(Graphics2D g2d) {
|
||||
g2d.setRenderingHint(
|
||||
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(
|
||||
RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||
}
|
||||
|
||||
public static String randomString(int n){
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz23456789$#%@&?";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(int i=0; i<n; i++){
|
||||
int index = (int)(characters.length() * Math.random());
|
||||
stringBuilder.append(characters.charAt(index));
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
public static String randomString(int n) {
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz23456789$#%@&?";
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < n; i++) {
|
||||
int index = (int) (characters.length() * Math.random());
|
||||
stringBuilder.append(characters.charAt(index));
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static int randomNumber(int min,int max){
|
||||
return (int)(Math.random() * ((max - min) +1)) + min;
|
||||
}
|
||||
public static int randomNumber(int min, int max) {
|
||||
return (int) (Math.random() * ((max - min) + 1)) + min;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user