Created
March 19, 2015 10:42
-
-
Save michalbcz/00a069c7a2542ea7fa2a to your computer and use it in GitHub Desktop.
jax-rs (Resteasy) - dynamic image resource sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GET | |
@Path("/images/{id}") | |
@Produces("image/png") | |
public Response getImages(final @PathParam("id") String id) { | |
StreamingOutput imageStreamingOutput = new StreamingOutput() { | |
@Override | |
public void write(OutputStream output) throws IOException, WebApplicationException { | |
final BufferedImage image = new BufferedImage(250, 250, BufferedImage.TYPE_INT_RGB); | |
Graphics g = image.getGraphics(); | |
g.setFont(g.getFont().deriveFont(30f)); | |
g.drawString(id, 100, 100); | |
g.dispose(); | |
ImageIO.write(image, "png", output); | |
} | |
}; | |
return Response.ok(imageStreamingOutput, MediaType.valueOf("image/png")).build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment