Providing the image resource
There are several things you need to know about providing an image resource in a Genero program.
Supported image formats
Genero supports various image data formats, typically PNG, JPEG and SVG. However, the supported image formats depend on the type of front-end used. Check the front-end platform documentation for supported image formats.
True Type Font (TTF) files are also supported. The TTF format is used when image-to-font-glyph mapping is enabled by specifying a mapping file in the FGLIMAGEPATH environment variable.
Image resolution
Consider using the appropriate image resolution for the target front-end platform. For example, mobile devices have a much higher pixel density (a higher resolution) than desktop monitors. An image which looks nice on a desktop can appear small or as an unscaled image on a mobile device.
Static versus dynamic images
- For static images (such as button icons), set the image resource in the image
attribute (
IMAGE
,IMAGELEAF
, and so on). See Static images. - For dynamic images (such as image fields displaying photos from a database), the
image resource is specified with the field/variable value, to be rendered in a form field. The form
field is typically defined as an
IMAGE
item, or anIMAGECOLUMN
in a table view. For more details, see Runtime images.
Image resource lookup
The image data can be provided in different ways, depending on the image resource specification:
- As a Uniform Resource Locator (URL).
- As a simple image name (typical for icons).
- As a simple file name, typically with a .png or .jpg extension, or a relative or absolute file path.
Using an URL image resource
If the image specification starts with a URL prefix, the front-end will try to download the image from the location specified by the URL.
The network access to the Web server must exist and network bandwidth must be sufficient to rapidly download the images.
Image resource location (URL) | Description |
---|---|
http://location-specification |
HTTP server |
https://location-specification |
HTTPS server (HTTP over SSL/TLS) |
Using a simple image name (centralized icons)
If the image specification is a simple name (without a file extension), and the FGLIMAGEPATH environment variable defines an icon mapping file for the runtime system, the image name is converted to a font file and font glyph, based on the mapping file entries, and the image form item displays the glyph/icon found in the font definition file. The mapping file and the font definition file are centralized on the application server.
image-name=font-file:hexa-ordinal[:color-spec]
smiley=FontAwesome.ttf:f118
red_smiley=FontAwesome.ttf:f118:#8B0000
An image resource (IMAGE
attribute, IMAGECOLUMN
value, and so on) with the name "smiley
" will be mapped to the
glyph with ordinal position 0xf118
in the
FontAwesome.ttf font file, and the image resources using
"red_smiley
" will use the same glyph, but will get a red color.
defaultTTFColor
style
attribute:<StyleList>
<Style name="Window.important">
<StyleAttribute name="defaultTTFColor" value="red" />
</Style>
...
A default mapping file named "image2font.txt" and the "FontAwesome.ttf" font file are provided in FGLDIR/lib. If FGLIMAGEPATH is not defined, the runtime system will use these files to make the image to font glyph mapping.
fsType
field in the OS/2 table to zero. This
modification can be done with freeware tools like ttembed.It is possible to mix several plain image file directories with several image-to-font glyph mapping files in FGLIMAGEPATH. The list of mapping files and directories defines the order of precedence, for example:
$ export FGLIMAGEPATH="/var/myapp/myimages:\
/var/myapp/myicons.txt:/var/myapp/fontfiles:\
$FGLDIR/lib/image2font.txt:$FGLDIR/lib"
/var/myapp/myimages
: Directory where plain image files can be found/var/myapp/myicons.txt
: Custom image-to-font-glyph mapping file (icons)/var/myapp/fontfiles
: Font files used by the myicons.txt mapping file$FGLDIR/lib/image2font.txt
: Default icon mapping files (using FontAwesome.ttf)$FGLDIR/lib
: Location of the default FontAwesome.ttf file
Consider defining your own image mapping file and make FGLIMAGEPATH point to your own files.
mobile.environment.FGLIMAGEPATH
entry in
FGLPROFILE. Use $FGLAPPDIR and $FGLDIR placeholders to include the current
appdir
(program file directory) and the FGL runtime system
directory, respectively.See FGLIMAGEPATH for more details about this environment variable.
Using file names or paths
If the image specification is a simple file path (without an URL prefix, and typically with an image file extension), the front-end gets the image file from the runtime system.
The image file is searched on the platform where the program executes. The runtime system uses the FGLIMAGEPATH environment variable when searching for the images. If FGLIMAGEPATH is not set, the current working directory is searched for the image files.
If the image file is specified without a file extension, Genero will try to find the file with a predefined list of extensions (.png, .jpg, etc). The search depends on the name of the image file, the list of directories defined in FGLIMAGEPATH, and the predefined list of file extensions. This search procedure was implemented to allow different types of front-ends to pass the preferred image compression formats, and to allow you to define the image name in your forms without any extension. However, it is much more efficient to specify the image file with a portable extension. Using image files with extensions is strongly recommended.
Application images in Web Components
Web Components can display static images (part of the Web Component assets), and
application images provided at runtime (for example, a photo gallery web component).
In order to provide application images to a Web Component, the program must use the
ui.Interface.filenameToURI()
method to convert the local
file name to a URI that can be accessed by the front-end.
For more details, see Using image resources with the gICAPI web component.