Create a png image from a string lazarus / 39-Graphics ---------------------------------------------------------------------- PepperJules · 2025-07-09 15:32 I have difficulties to find out where to start, and I hope some of you experienced coders can point me in the right direction... I have a variable containing a string, and would like to create a png image from it. I would like to be able to set the text font, text color and text size, as well as the background color of the image (black, white or alpha). The image file format can also be jpg. What units/components should I be looking at? Platform = windows ---------------------------------------------------------------------- thijsvandien · 2025-07-09 16:53 Forget about the final image format for now. As long as you can produce a bitmap (basically a grid of pixels), it can later be converted to something more efficient. JPEG doesn't support transparency, however. Here's an intro: https://wiki.freepascal.org/Developing_with_Graphics ---------------------------------------------------------------------- jamie · 2025-07-09 21:56 There are some considerations you must examine.  You do not indicate if this string variable is to be used over the network, so that would mean not using upper 128 chars?  You have a choice of using a encoding 64 functions as such.  a human readable string would mean encoding the image into a Hex string, which will make it twice the size but at least if can be contained in a string without issues.  You need to specify more details! Jamie ---------------------------------------------------------------------- TBMan · 2025-07-09 22:55 Quote from: PepperJules on July 09, 2025, 05:32:46 pmI have difficulties to find out where to start, and I hope some of you experienced coders can point me in the right direction... I have a variable containing a string, and would like to create a png image from it. I would like to be able to set the text font, text color and text size, as well as the background color of the image (black, white or alpha). The image file format can also be jpg. What units/components should I be looking at? Platform = windows It sounds like you want to learn how to code run-length encoded image files. *OR You want to save current display options in a program which is different. ---------------------------------------------------------------------- H₂SO₄ · 2025-07-10 05:05 Here's a very barebones example program that creates an image, draws some text on it, and saves it as a  .png: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Example; {$mode objfpc}{$H+} uses  Interfaces, Graphics; procedure DrawExample(const Text: String);var  Image: TPicture;begin   // Create blank 256 x 256 image  Image := TPicture.Create();  Image.PNG.SetSize(256, 256);   // Draw something using the canvas  with Image.PNG.Canvas do begin     // Fill background color    Brush.Color := TColor($F7F4F0);    Brush.Style := bsSolid;    FillRect(0, 0, Image.Width, Image.Height);     // Draw text    Font.Color := clTeal;    Font.Name := 'Arial';    Font.Height := 48;  TextOut(16, 96, Text);  end;   // Save & destroy image  Image.SaveToFile('test.png');  Image.Free();end; begin  DrawExample('Hello World!');end. Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i fpc example.pas ^    -FuC:\lazarus\lcl\units\x86_64-win64 ^    -FuC:\lazarus\lcl\units\x86_64-win64\win32 ^    -FuC:\lazarus\components\lazutils\lib\x86_64-win64 If you want to do anything involving transparency that is more complicated than filling non-antialiased rectangles (i.e. pretty much anything), I'd encourage you to switch to BGRABitmap; it's a household name in the Free Pascal / Lazarus ecosystem and has lots of features, although its documentation is a bit lacking. ---------------------------------------------------------------------- Boleeman · 2025-07-10 05:29 And a Text on Paintbox example. ---------------------------------------------------------------------- paweld · 2025-07-10 10:57 or BGRABitmap: https://forum.lazarus.freepascal.org/index.php?topic=48431.0 https://wiki.freepascal.org/BGRABitmap_tutorial_12