DelphiFAQ Home Search:

Convert text to a GIF image

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

I need to dynamically display buttons on my web site that contain some text (not static text). How can I create a GIF image showing text?

Answer:

You need to get a TGIFImage component first - or decide to use the JPEG format. For text buttons, GIF will generate smaller files though at better quality.
Ideally you should use the PNG file format - they are the smallest at lossless quality.
However, I don't know of a PNG unit.

See the article referenced above where to get a TGIFImage component.

Then use the procedure from below.

procedure TxtToGif(sText, sFileName: string);
var
  temp: TBitmap;
  GIF: TGIFImage;
begin { TxtToGif }
  temp := TBitmap.Create;
  try
    temp.Height := 400;
    temp.Width := 60;
    temp.Transparent := true;
    temp.Canvas.Brush.Color := colFondo.ColorValue;
    temp.Canvas.Font.Name := Fuente.FontName;
    temp.Canvas.Font.Color := colFuente.ColorValue;
    temp.Canvas.TextOut(10, 10, sText);
    Imagen.Picture.Assign(nil);

    GIF := TGIFImage.Create;
    try
      // Convert the bitmap to a GIF
      GIF.Assign(temp);
      // Save the GIF
      GIF.SaveToFile(sFileName);
      // Display the GIF
      Imagen.Picture.Assign(GIF);
    finally
      GIF.Free;
    end; { try }

  finally
    temp.Destroy;
  end; { try }
end; { TxtToGif }

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.