hi,
it remains pretty simple :)
regards
Thomas
<map:match pattern="time.jpg">
<map:call function="intercept" />
</map:match>
<map:match pattern="generate.image">
<map:read type="timeimg"/>
</map:match>
function intercept() {
var backgroundVariable = '#44ffFF';
var text = String(new Date());
cocoon.sendPage("generate.image", {
"background" : backgroundVariable,
"text" : text,
"size" : 55.3
});
}
public class TestImageReader extends AbstractReader {
public String getMimeType() {
return "image/png";
}
private Object get(String name, Scriptable s) {
Object o = s.get(name, s);
while (o instanceof Wrapper) {
o = ((Wrapper) o).unwrap();
}
return o;
}
@Override
public void generate() throws IOException, SAXException,
ProcessingException {
Object contextObject = FlowHelper.getContextObject(objectModel);
Object text = null;
Object background = null;
float fontsize = 80.f;
if (contextObject instanceof Scriptable) {
Scriptable s = (Scriptable) contextObject;
background = get("background", s);
text = get("text", s);
Object size = get("size", s);
if (size instanceof Number) {
fontsize = ((Number) size).floatValue();
}
}
if (text == null)
text = DateFormat.getDateTimeInstance().format(new Date());
if (background == null)
background = "#FF0000";
Font font = Font.decode(Font.SERIF).deriveFont(fontsize);
TextLayout textLayout = new TextLayout(String.valueOf(text),
font, new FontRenderContext(null, true, true));
Rectangle2D bounds = textLayout.getBounds();
BufferedImage image = new BufferedImage((int)
(bounds.getWidth() + 0.5), (int) (bounds.getHeight() + 0.5),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.decode(String.valueOf(background)));
textLayout.draw(g, (float) -bounds.getX(), (float) -bounds.getY());
g.dispose();
ImageIO.write(image, "png", this.out);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]