Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Image operators

texttoimage, image and imagefile from eZTemplateImageOperator - rendering text as an image with a TrueType font from texttoimage.ini, composing layers, and reading an image file's size - which ones write files under…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/template-operators/image-operators.md

On this page

Image operators

Three operators of eZTemplateImageOperator (lib/eztemplate/classes/eztemplateimageoperator.php), registered through lib/eztemplate/classes/eztemplateautoload.php, work with images through PHP's GD extension (the class checks for ImageTTFBBox, ImageCreate, ImageTTFText, ImagePNG and the other functions it needs, and logs an error instead of working when one is missing):

  • texttoimage renders a text as a PNG image with a TrueType font;
  • image combines layers into one image;
  • imagefile reads an existing image file.

They have nothing to do with the images of content objects, which come from the image datatype and its aliases. All three return an image object (eZImageLayer, eZImageTextLayer or eZImageObject), which prints as an <img> tag and offers the attributes filepath, filename, width, height, alternative_text, imagepath and has_size.

Contents

  1. Settings: texttoimage.ini
  2. texttoimage
  3. image
  4. imagefile
  5. Related pages

Settings: texttoimage.ini

settings/texttoimage.ini holds the paths and the font classes:

SettingValue on a development installationMeaning
[ImageSettings] UseCacheenabledreuse an image already rendered with the same text and settings
[PathSettings] FontDir[]design/standard/fontswhere the .ttf fonts are looked for
[PathSettings] CacheDirvar/cache/texttoimagewhere rendered images are written
[DefaultSettings]Family=1942, PointSize=40, white background, black textused when a class does not say otherwise
[1942], [a_d_mono], [sketchy], [smartie] ...font family and adjustmentsthe classes a template can name

texttoimage

texttoimage

Renders the piped text with the font settings of a class, overridden by any parameter given. The image is written to <CacheDir>/imagetext/ under a name made from an MD5 of the text and the settings; with UseCache an existing file is reused.

ParameterTypeRequiredDefault
classstring, a section of texttoimage.inino'default' (falls back to [DefaultSettings])
familystring, font file name without .ttfnofrom the class
pointsizeintegernofrom the class
angleintegernofrom the class
bgcolorcolor (#rrggbb or an array of three numbers)nofrom the class
textcolorcolornofrom the class
x, y, w, hinteger adjustmentsnofrom the class
usecacheboolean, or a string used as the cache nameno[ImageSettings] UseCache
storeimagebooleannotrue

Input: the text, piped. Returns an eZImageTextLayer. When the font is not found it returns nothing; when the font cannot be opened it logs "Could not open font". Generated reference: texttoimage.

It writes files. The template below was rendered once on a development installation while this page was prepared, and it created the directory var/cache/texttoimage/imagetext/ with the PNG file (a cache directory: it can be cleared, and the image is made again on the next request):

{'Fit & Healthy'|texttoimage( '1942' )}

Its output:


<img border="0" src="/var/cache/texttoimage/imagetext/b/d/3/bd3fdc7ef41d4f843b93d8d9703be5d4/Fit_amp_Healthy.png" alt="Fit &amp;amp; Healthy" width="450" height="52" />

Note the alt text: the operator escapes the text with htmlspecialchars() when it creates the layer ($alternativeText), and the <img> output escapes it again, so & arrives as &amp;amp;. Pass text without characters that need escaping, or write the <img> tag yourself from imagepath, width and height.

image

image

Builds one image from layers. Every parameter is either a string, which becomes the alternative text, or an array of a layer and a hash of placement options: halign (left, right, center), valign (top, bottom, center), x, y, xrel, yrel and transparency. The result is written to <CacheDir>/imageobject/ (reused with UseCache).

ParameterTypeRequiredDefault
layers and alternative textarray( layer, hash( options ) ) or string, any numberyesnone

Input: none. Returns an eZImageObject. Generated reference: image.

It writes files, like texttoimage. This template, also rendered once on a development installation, created var/cache/texttoimage/imageobject/:

{image( array( 'Fit & Healthy'|texttoimage( '1942' ), hash( 'halign', 'center', 'valign', 'center' ) ), 'Fit and Healthy' )}

Its output:


<img border="0" src="/var/cache/texttoimage/imageobject/5/e/1/5e1e308e65728a71d3bcfdcfd00dbd81/Fit_and_Healthy.png" alt="Fit and Healthy" width="450" height="52" />

imagefile

imagefile

Reads an image file and returns it as a layer: eZImageLayer::createForFile() reads the size with getimagesize() and loads the image into memory. Nothing is written. The alternative text is the file name without its extension.

ParameterTypeRequiredDefault
filenamestring, a path relative to the installationyesnone
optionsarraynoarray()

Input: none. Returns an eZImageLayer, which can be used as a layer of image. Generated reference: imagefile.

{def $img = imagefile( 'design/standard/images/add.png' )}
filepath: {$img.filepath}
filename: {$img.filename}
size: {$img.width} x {$img.height} (has_size: {$img.has_size|choose( 'no', 'yes' )})
alternative_text: {$img.alternative_text}

Output:

filepath: design/standard/images
filename: add.png
size: 16 x 16 (has_size: yes)
alternative_text: add

The imagefile example gave the same output compiled on a development installation. The two writing examples were not run a second time, interpreted or compiled.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x