On the fly graphic text

Posted on 2005-05-12
Last Modified: 2010-03-31
I am sure I once used a program that took text an transformed it to a graphic.

It was a rectangle o a certain color with the text of a certain font.

The rectangle, font and color where the parameters. It was simple and did the job

I need it but cannot find any

Question by:robrodp
    LVL 92

    Expert Comment

    can you explain a little more exactly what you are after?

    Heres some examples of transforing text if that helps
    LVL 13

    Expert Comment

    Hi robrodp,

    not sure but this may be what u want:

    LVL 13

    Accepted Solution

    also check this one, I think this is what u need:

    Author Comment

    The idea is you pass through asp code some text a word for example: Mexico (or whatever) and you give a program ( I remember it was .class java) the characteristics you need, size, colors, and font ant the html displays the text as a graphic
    LVL 13

    Expert Comment


    check the last url I think this is what u need
    LVL 92

    Expert Comment

    LVL 29

    Assisted Solution

    Here's an example of a servlet that does just that, as the servlet checks the request parameters for String to write into the image.

    package com.bloodredsun.servlet;

    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;

    import javax.imageio.ImageIO;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;

    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

     * @author bloodredsun
     * @return

    public class ImageServlet extends HttpServlet {

         public void doGet(HttpServletRequest req, HttpServletResponse resp)
              throws ServletException, IOException {

              ServletOutputStream sos = resp.getOutputStream();
              String imgString = req.getParameter("str")!=null ? req.getParameter("str") : "Test Me" ;

              // Create an image to output
              RenderedImage rendImage = myCreateImage( imgString );

              try {
                   ImageIO.write(rendImage, "jpg", sos);
              } catch (IOException e) {
                   System.out.println("Error:" + e.getMessage());

         public void doPost(HttpServletRequest req, HttpServletResponse resp)
              throws ServletException, IOException {
              doGet(req, resp);

          * @return RenderedImage
         private RenderedImage myCreateImage( final String pString ) {
              int width = 100;
              int height = 50;

              // Create a buffered image in which to draw
              BufferedImage bufferedImage =
                   new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

              // Create a graphics contents on the buffered image
              Graphics2D g2d = bufferedImage.createGraphics();

              // Draw graphics
              g2d.fillRect(0, 0, width, height);
              g2d.drawString(pString, 50, 25);

              // Graphics context no longer needed so dispose it

              return bufferedImage;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Title # Comments Views Activity
    Using java code in .Net/c#: namespace issue 3 38
    MaxSpan challenge 9 49
    nested interface 5 29
    scores100 challenge 3 67
    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now