Skip to content

Commit

Permalink
Merge pull request #1 from ESSICS/2-more-parameters
Browse files Browse the repository at this point in the history
2 more parameters
  • Loading branch information
berryma4 authored Aug 23, 2016
2 parents ca98661 + ad6f1d9 commit 5e710dc
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
*~
Backup*.cdr
target/

ImageLabeler/nbactions.xml
2 changes: 1 addition & 1 deletion ImageLabeler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.csstudio</groupId>
<artifactId>ImageLabeler</artifactId>
<version>1.0</version>
<version>2.0</version>
<packaging>jar</packaging>

<name>ImageLabeler</name>
Expand Down
131 changes: 92 additions & 39 deletions ImageLabeler/src/main/java/org/csstudio/imagelabeler/ImageLabeler.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.csstudio.imagelabeler;


import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
Expand All @@ -14,42 +13,96 @@
import java.util.logging.Logger;
import javax.imageio.ImageIO;


@SuppressWarnings( "ClassWithoutLogger" )
public class ImageLabeler {

private static Font loadFont(String name) {
try {
Font font = Font.createFont(Font.TRUETYPE_FONT, ImageLabeler.class.getResourceAsStream(name));
return font.deriveFont(Font.PLAIN, 21f);
} catch (FontFormatException ex) {
Logger.getLogger(ImageLabeler.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ImageLabeler.class.getName()).log(Level.SEVERE, null, ex);
}
throw new RuntimeException("Couldn't load");
}

public static void main(String[] args) throws Exception {
if (args.length != 5) {
System.out.println("Usage: [version] [xPosition] [yPosition] [template.bmp] [splash.bmp]");
System.exit(-1);
}

String version = args[0];
String fontName = "AGENCYR.TTF";
String inFile = args[3];
String outFile = args[4];
int xPosition = Integer.parseInt(args[1]); //394;
int yPosition = Integer.parseInt(args[2]); //53;
BufferedImage image = ImageIO.read(new File(inFile));
Graphics2D g = (Graphics2D) image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Font font = loadFont(fontName);
g.setFont(font);
g.setTransform(AffineTransform.getTranslateInstance(0.3, 0));
int length = g.getFontMetrics().stringWidth(version);
g.drawString(version, xPosition - length, yPosition);
ImageIO.write(image, "bmp", new File(outFile));
}

@SuppressWarnings( "UseOfSystemOutOrSystemErr" )
public static void main( String[] args ) throws Exception {

if ( ( args.length != 3 + 2 ) && ( args.length != 3 + 2 + 3 ) && ( args.length != 3 + 2 + 3 + 3 ) ) {
System.out.println(
"Usage: java -jar ImageLabeler-2.0.jar <version> <xPosition> <yPosition> <template.bmp> <splash.bmp>\n" +
" [<affiliation> <xAffPosition> <yAffPosition>\n" +
" [<icon> <xIconPosition> <yIconPosition>]]\n" +
"Where:\n" +
" <version> is the version string,\n" +
" <xPosition> is the right X coordinate of the version string,\n" +
" <yPosition> is the baseline Y coordinate of the version string,\n" +
" <template.bmp> is the pathname of the template bitmap file,\n" +
" <splash.bmp> is the pathname of the generated (annotated) splash-screen bitmap\n" +
" <affiliation> is an optional affiliation text\n" +
" <xAffPosition> is the left X coordinate of the affiliation string,\n" +
" <yAffPosition> is the baseline Y coordinate of the affiliation string,\n" +
" <icon> is an optional icon\n" +
" <xIconPosition> is the left X coordinate of the icon,\n" +
" <yIconPosition> is the top Y coordinate of the icon.\n"
);
System.exit(- args.length);
}

String version = args[0];
int xPosition = Integer.parseInt(args[1]); //394;
int yPosition = Integer.parseInt(args[2]); // 53;
String inFile = args[3];
String outFile = args[4];
BufferedImage image = ImageIO.read(new File(inFile));
Graphics2D g = (Graphics2D) image.getGraphics();

g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

String fontName = "AGENCYR.TTF";
Font font = loadFont(fontName);

g.setFont(font);
g.setTransform(AffineTransform.getTranslateInstance(0.3, 0));

int length = g.getFontMetrics().stringWidth(version);

g.drawString(version, xPosition - length, yPosition);

if ( args.length >= 3 + 2 + 3 ) {

String affiliation = args[5];
int xAffPosition = Integer.parseInt(args[6]); // 19;
int yAffPosition = Integer.parseInt(args[7]); //151;

g.drawString(affiliation, xAffPosition, yAffPosition);

}

if ( args.length >= 3 + 2 + 3 + 3 ) {

BufferedImage icon = ImageIO.read(new File(args[8]));
int xIconPosition = Integer.parseInt(args[9]); // 19;
int yIconPosition = Integer.parseInt(args[10]); //151;

g.drawImage(icon, null, xIconPosition, yIconPosition);

}

ImageIO.write(image, "bmp", new File(outFile));

}

private static Font loadFont( String name ) {

try {

Font font = Font.createFont(Font.TRUETYPE_FONT, ImageLabeler.class.getResourceAsStream(name));

return font.deriveFont(Font.BOLD, 21f);

} catch ( FontFormatException ex ) {
Logger.getLogger(ImageLabeler.class.getName()).log(Level.SEVERE, null, ex);
} catch ( IOException ex ) {
Logger.getLogger(ImageLabeler.class.getName()).log(Level.SEVERE, null, ex);
}

throw new RuntimeException("Couldn't load");

}

}

0 comments on commit 5e710dc

Please sign in to comment.