Skip to content

kwon37xi/rits

Repository files navigation

Realtime Image Text Service

Realtime Image Text Service is for creating heading image text from any TTF fonts. Actually this is not for usual long text.

If you want long text data images, you'd better refer to TextImageGenerator.

rits-core API

  • Refer to DefaultImageTextGeneratorRealImageTest.java
  • This api support flexible image height. It will calculate the strings' total height, then decide the image height.

Requirements

  • Java 6

Example

// Set font infomation
int style = Font.PLAIN;
float pixel = 26F;
Font font = Font.createFont(Font.TRUETYPE_FONT, new File("/path/to/ttf/font/yourfont.ttf")).deriveFont(style, pixel);

// Set image attributes.
ImageTextParams params = new ImageTextParams();
params.setFont(font);
params.setWidth(500); // image width
params.setBackgroundColor(Color.decode("#f0f0f0"));
params.setForegroundColor(Color.BLUE);
params.setMargin(new Margin(25, 25));
params.setLineHeight(5); // line height pixel
params.setBreakIterator(BreakIterator.getWordInstance()); // Line wrapping rule.

ImageTextGenerator generator = new DefaultImageTextGenerator(params);

// add texts
generator.writeln("Realtime Image Text Service");
generator.writeln("실시간 이미지 텍스트 생성 서비스");
generator.newLine();
generator.writelnWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
        "Duis sapien nibh, auctor at urna non, rutrum fermentum metus.");

// generate image file
generator.generateImage(ImageFormat.PNG, new File("example.png"));

You will have like the following image.

generated image

Note

  • New lines(\n) in the string are ignored. If you want a new line, you must call ImageTextGenerator.newLine() explicitly.

rits-server

TODO

rits-server is a web application which is based on rits-core. This application serves requests from another applications or web browsers to generate images on the fly.

Requirements

  • Java 6
  • Servlet container which support java servlet 3.0. (Tomcat 7)

Releases

No releases published

Packages

No packages published