Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

For precise, repeatable text-to-image output in Python, use Pillow: measure the text first, allocate padding around its true bounds, draw with an appropriate font and layout settings, then save as PNG or JPEG. Use ImageMagick for command-line and batch work, SVG when you need resolution-independent vector text, and Canvas for browser-side drawing and bitmap export.

Choose the method that fits the job

Method Best fit What the output preserves
Pillow Python applications requiring measured text layout, multilingual direction, and repeatable raster output. Pixels; text is no longer editable text after rasterization.
ImageMagick Shell pipelines, batch jobs, and annotating existing images. Pixels.
SVG Resolution-independent output or text that should remain represented as vector elements. Vector structure, though font availability can affect how text renders.
Canvas Drawing in a browser and exporting a bitmap. Pixels after export.

If the text conveys essential information, provide an HTML text alternative or accessible document alongside the rendered image. Pixels alone are not searchable or copyable as text.

Render text to PNG or JPEG with Pillow

Install Pillow in your Python environment with python -m pip install Pillow. The example below loads a TrueType/OpenType font, measures a single line, includes room for glyphs that extend beyond the nominal baseline, draws the text onto a transparent image, and saves a PNG.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from PIL import Image, ImageDraw, ImageFont

text = "Hello, world!"
font_path = "/path/to/your/font.ttf"  # Use a font installed on your system.
font = ImageFont.truetype(font_path, 72)
padding = 24

# Measure the ink bounds relative to the drawing origin.
left, top, right, bottom = font.getbbox(text, stroke_width=2)
width = right - left + padding * 2
height = bottom - top + padding * 2

image = Image.new("RGBA", (width, height), (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
draw.text(
    (padding - left, padding - top),
    text,
    font=font,
    fill=(20, 20, 20, 255),
    stroke_width=2,
    stroke_fill=(255, 255, 255, 255),
)
image.save("text.png")

Replace the example font path with a real font file. If Pillow cannot open the font, check both the path and that the file is a supported TrueType or OpenType font. Pillow’s ImageFont documentation explains font loading and text measurement; the ImageDraw documentation describes drawing and multiline options.

#1 Best Overall
HP Smart Tank 5003 Wireless All-in-One Ink Tank Printer, Scanner, Copier with up to 3 Years of Ink Included, Best-for-Home, Cartridge-Free Refillable, AI-Capable (9B2D3A)
  • THE LAST PRINTER YOU'LL EVER NEED – Set it up once and print with confidence; no complicated maintenance, just easy, reliable printing you can count on
  • FULLY LOADED WITH SAVINGS – Best for low-cost, high-volume printing—up to 3 years of HP Ink included; get up to 6,000 color or black pages right out of the box
  • KEY FEATURES – Print, copy and scan, plus borderless prints, mobile and wireless printing
  • MESS-FREE REFILL – Replenish ink with HP's easy-access, mess-free refill system; simply plug the ink bottles into this cartridge-free ink tank and let them drain—no squeezing, no spilling
  • BEST PRINT QUALITY, PERIOD – Sharper text, richer colors, only with HP Smart Tank

Why measurement and padding matter

Text width is not reliably equal to character count multiplied by font size. Glyphs have different advances, and visible shapes can extend above or below the baseline. Pillow’s getbbox() returns a bounding box in pixels relative to the given anchor when rendered with the selected font and applicable direction, features, and language. The offsets may be negative, which is why the example subtracts the left and top bounds when choosing the drawing position.

Include extra room for strokes, shadows, and line spacing as appropriate. If the text is clipped, inspect the measured bounds and increase padding rather than guessing a fixed image size. Measurement and drawing must use compatible settings: for example, include the stroke width when measuring text that will be outlined.

Multiline layout and alignment

For multiple lines, use multiline_text() and its spacing and alignment settings. Set the image dimensions based on the rendered lines and chosen line spacing; do not assume that each line consumes precisely the nominal font size. Pillow also exposes anchors to position text relative to a defined point instead of manually compensating for offsets. Consult the ImageDraw reference for the current signatures and behavior of multiline_text(), anchor, align, and spacing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Direction, language, and font coverage

For scripts that need specialized shaping, choose a font with glyphs for the input and pass Pillow’s direction and language settings where appropriate. Documented directions include left-to-right (ltr), right-to-left (rtl), and top-to-bottom (ttb). OpenType feature controls are available when Pillow is built with libraqm support. See the Pillow ImageDraw reference and ImageFont reference for details.

Rank #2
Sharper Image Smartphone Photo Printer
  • #1 Bestselling Photo Printer Compact and easy to use Prints 4x6 color photos in seconds Pairs wirelessly with your mobile device FREE App for editing, applying filters, and more

Test the actual text you intend to ship, including punctuation, combining marks, emoji, and unusually long lines. A font may lack a glyph or render it using a fallback, changing both appearance and dimensions. Direction and language settings do not supply missing glyphs.

PNG or JPEG?

  • PNG: a good default for sharp text edges, UI labels, diagrams, and transparent backgrounds. It is lossless.
  • JPEG: useful when reducing file size matters more than preserving crisp edges, especially over photographic backgrounds. Compression can create artifacts around small text.

For a transparent canvas, create an RGBA image and save as PNG. JPEG does not retain transparency. Inspect the result at its intended display size and check text contrast against the background.

Draw text with ImageMagick

ImageMagick suits shell-based composition, repeatable command pipelines, and labeling an existing image. Its -annotate option places text, while -draw provides a lower-level drawing route. The following creates a centered text image; it uses a named font, so use a font name available to your ImageMagick installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
magick -size 1200x300 canvas:white 
  -font DejaVu-Sans 
  -pointsize 72 
  -fill black 
  -gravity center 
  -annotate +0+0 "Hello" output.png

Adjust the canvas size, font, point size, fill, and gravity to suit the design. ImageMagick’s drawing guide covers the -draw primitive and text controls. For an existing image, pass the image as the input and use -annotate with suitable placement; the exact coordinates depend on its dimensions and the desired label location. Its command-line options reference documents options such as -font, -pointsize, -fill, -gravity, -stroke, and -undercolor.

Rank #3
Sale
SUPVAN T50M Pro Bluetooth Label Maker Machine with Tape, Black
  • For Home and Small Business: Prints 3/4" - 2" wide labels; ideal for home organization (storage bins, bottle, jar, food container, etc.), small business (address, product info, QR Code, barcode, brand logo, etc.), or school and office supplies (name tag, folder, documentation, etc.)
  • Versatile App Editing Function: Easily add images from your phone, tablet or PC; customize your labels with 30+ fonts, 50+ frames, and 660+ icons; all free to use
  • Enhanced Image Quality: The App delivers precise image processing capabilities, resulting in a high-resolution and clear output; enhanced aesthetic appeal, formality, and richness
  • Easy to Use: The APP is completely free, requires no registration; features auto label size recognition; no ink or toner needed; create labels quickly and easily
  • Versatile Label Compatiblity: Compatible with square, round, address, cable, jewelry and file labels, to meet all your needs; ensuring a perfect fit for any project; keeps everything neat and tidy

When SVG or Canvas is a better fit

Use SVG for scalable text

SVG is appropriate when an image must scale without becoming pixelated or when retaining vector elements matters. Text can remain represented as text in the SVG rather than being converted to pixels, although rendering still depends on the font available where it is displayed. SVG can also be used in HTML, CSS, SVG, and Canvas’s drawImage() function.

When SVG is loaded as an image, browsers may disable JavaScript and external resources. If rendering depends on assets such as fonts, embed or inline the required resources where necessary rather than assuming a remote asset will load.

Use Canvas for browser-side drawing

Canvas is useful when the browser already has the text and layout inputs and the goal is to compose a bitmap there. Draw into the canvas, then export the bitmap using the browser’s canvas export APIs. Keep the original text in the page or an accessible equivalent: exported pixels do not carry the same search, copy, or screen-reader meaning as HTML text.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prevent clipping and improve output quality

  • Measure before allocating: use the same font and relevant layout settings as the final draw operation.
  • Leave safety space: account for ascenders, descenders, strokes, shadows, and line spacing.
  • Prefer anchors: use a defined text anchor for alignment instead of accumulating hand-tuned x/y corrections.
  • Choose adequate resolution: render at final size or deliberately higher, then downsample with a high-quality filter if needed.
  • Check real input: validate long strings, punctuation, combining marks, and multilingual text.
  • Check contrast: inspect the image at the size and background where people will see it.
  • Retain accessible text: provide the original string in metadata or adjacent HTML when searchability, copying, or assistive technology matters.

Troubleshoot common rendering problems

The text is cut off

Recalculate the bounding box and offsets for the same text, font, direction, and stroke settings used to draw. Add padding around all sides, including for outlines and shadows. For multiple lines, include the selected spacing and alignment in your layout calculation.

Rank #4
Sale
BESHENG Handheld Inkjet Printer Gun PT3000 Printing Height 0.08-0.5Inch Inkjet Coder with Original Fast-Drying Ink for Text QRCode/Barcode/Batch Number/Label/Image/Date Printer with Touch Screen
  • Prints a Variety of Content - From variable text, variable QRCODE, picture, production date, expiry date, serial batch and lot number, label and barcode, BESHENG handheld inkjet printer supports printing various content to cater to different business needs and individual needs
  • Versatile Material Compatibility - BESHENG handhled inkjet printer gun is suitable for use on a wide range of materials, such as paper, carton, wood, metal, plastic bottle, ceramics, aluminum can, glass bottle, stone, pvc pipe, fiber cloth etc., Handheld date coder can print on multiple surfaces. If printing on a circular or curved surface, it would be better to use a positioning plate to print together
  • Original Fast-drying Ink - BESHENG handheld inkjet coder is equipped with a black fast-drying ink, which deliver clear, crisp and sharp prints while drying rapidly, allowing for improved efficiency and convenience. The ink is waterproof after ink drying
  • Printing Features - BESHENG PT3000 handheld inkjet date printer print height is from 0.08inch to 1 inch. You can print 1-5 lines at a time. BESHENG handheld printer has built-in 28 languages (Chinese, English, Japanese, Korean, Spanish, Portuguese etc.). You can directly edit the printed content on the machine, or import text(txt.) and pictures(BMP) through the U disk
  • Intuitive Interface and Package - BESHENG Handheld inkjet printer featuring a 4.3-inch touchscreen display for easy operation. Handheld inkjet date coder is compact and lightweight design allows for on-the-go printing. Package: 1× Handheld Printer, 1× Touch Pen, 1× Power adapter, 1× U-disk, 1× Ink cartridge(Black), 1× Sheet Metal Positioner, 1× Instruction book, 1x Portable Case. BESHENG will provide technical support

Characters appear as boxes or incorrect symbols

The selected font may not contain the necessary glyphs. Choose a font with coverage for every script and symbol in the input, and test emoji and combining characters independently. Do not assume a successful font load means every requested character exists.

Right-to-left or complex-script text looks wrong

Set the relevant direction and language when drawing, and confirm that the Pillow installation supports the shaping features you need. OpenType feature options require libraqm support according to Pillow’s documentation. Verify the exact font and string, since shaping and glyph coverage both affect the result.

The image is too soft or has a large file

For sharper small text and transparency, use PNG. If you rendered larger than needed, downsample with a high-quality filter. Use JPEG when compact size over a photo is more important than pristine text edges, and inspect the compression artifacts at the intended display size.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An SVG looks different when embedded

Image-context SVG rendering may disable JavaScript and external assets. Inline or embed required resources, and ensure the viewing environment has access to the fonts needed for the intended appearance.

Best Value
Sale
Epson Expression Premium XP-7100 Wireless Color All-in-One Inkjet Printer
  • CLEAR AND VIBRANT PRINT QUALITY ― All-in-one inkjet color printer produces sharp text for eye-catching documents and impressive color photos and graphics; Your next print job will be vivid and bright with this photo printer
  • PRINTER FOR HOME USE ― Designed to increase your productivity at home, this wireless color printer features a 30 page auto document feeder (ADF), auto 2-sided print, copy, and scan, multiple media feeds, and print quality you can count on
  • CREATIVITY MADE EASY ― Epson color printer provides creative versatility, allowing you to print photos and documents on specialty paper¹ and DVDs; You can even print bright and crisp borderless photos up to 8 X 10 in
  • SIMPLE FUNCTIONALITY ― Convenient features make printing, scanning, and copying a snap; Use the large, intuitive 4.3 in touchscreen to view, edit and print photos directly from USB or SD card slot²
  • CONVENIENT WIRELESS PRINTER ― Ultimate wireless plus ethernet; Easily print photos and documents directly from your tablet or smartphone³; Includes Wi-Fi direct for network-free printing⁴
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If by “render text as an image” you mean capturing a web page where the text is already laid out, a screenshot API can return the rendered page as an image rather than requiring you to recreate the browser layout. ScreenshotNeo is a website screenshot API and MCP server. For locally composed text graphics, Pillow, ImageMagick, SVG, or Canvas remains the right tool; ScreenshotNeo captures a URL.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie and consent banners are accepted and removed before capture, along with known newsletter popups and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers indicate the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

The free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free. Sign up for ScreenshotNeo free.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can I make text transparent outside the letters?

Yes. Create an RGBA image with a transparent background and save it as PNG; JPEG does not preserve transparency.

Does converting text to an image preserve accessibility?

Not by itself. Keep equivalent HTML text or an accessible document representation alongside the image when the text is important.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.