{img:image:phpthumb_params:info:param1:param2}

Description

Makes a resized version of an image (through phpThumb) and returns its URL, or a ready img or picture tag. By default (no info) it returns just the URL string, which you place inside your own img src attribute - the common use, with a file field as the image and a phpThumb size like w=150 and h=150 and zc=1. The phpthumb_params are passed straight to phpThumb (w, h, zc=1 for zoom-crop, iar=1 to keep aspect ratio, q for quality, and more). With no params the image path is returned unchanged. For an image uploaded to this install the URL points into a static image cache: the first request makes the thumbnail file, every later one is served by the web server directly. Any other image (from the file manager, the images folder or another domain), and some special parameters, go through the img.php handler of the install instead, whose path prefix is install-specific (for example /aaa or /aadev). The info parameter switches the output: im or img or imgb returns a ready img tag (imgb adds border 0; param1 becomes the title and alt text, param2 adds extra attributes); picture returns a responsive picture element with an avif or webp source. These tags get loading=lazy unless param2 sets loading itself; give loading=eager fetchpriority=high to the main image at the top of the page, where lazy loading delays its paint. img, imgb and picture (not im) also offer the image 1.5x and 2x as wide in srcset (an image 960 px or wider also 0.75x for phones; none wider than 2560 px), when the params only resize it, so phones and high-density screens get a sharp image; the 1x URL stays the same. A srcset of your own in param2 turns this off. url returns a URL for your own img src (relative, except a cached image whose upload folder is served from another domain), rawurl an absolute one. width, height, mime and imgtype return the size and type of the resized image. img, imgb, picture and hw need the size too: when w and h are both given with zc, iar or far it follows from the params, otherwise (and always for mime and imgtype) AA reads the image - the resized one from img.php, or without params the file itself - which is slow and works only for a reachable image. im and url never do. An empty image argument yields an empty string.

Parameters

image required

The image path or URL to show, usually a file-field getter such as {_#FILE____} or {img_url.........}. With an empty info the path is only turned into the URL (the file is not loaded); the metadata modes may load it (see the description). An empty value returns an empty string.

phpthumb_params optional

Resize and processing options passed straight to phpThumb, written as a URL query string. Common keys: w (width), h (height), zc=1 (zoom-crop to exactly w by h), iar=1 (keep aspect ratio inside w by h), q (JPEG quality), f (output format). Join several with the and-sign, for example w=150 and h=150 and zc=1. If left empty, the image path is returned unchanged (no resizing).

info optional default url

Selects what the command returns. Empty or url returns the URL for your own img src (a cache URL for an uploaded image, see the description), rawurl the absolute URL. im, img and imgb return a complete img tag (imgb adds border 0); picture returns a responsive picture element. width, height, mime and imgtype return the size and type of the resized image (slow unless the params fix the size, see the description). html or hw returns the height-and-width attribute string.

param1 optional

In the tag modes (im, img, imgb) this becomes the title and alt text of the img tag. In picture mode it is the picture title and alt. Tags are stripped and the value is escaped. Ignored by the URL and metadata modes.

param2 optional

In the tag modes (im, img, imgb) this is appended verbatim as extra HTML attributes on the img tag, for example class=thumb or width=150. In picture mode it is added to the inner img tag. Ignored by the URL and metadata modes.

Examples

virtual{img:photos/bee.jpg::width}
Expected(the image width in pixels, e.g. 800)
The metadata modes (width, height, mime, imgtype) open the actual file with getimagesize, so they only work for a reachable image and are slower. Virtual because the result depends on the real file.
virtual<img src="{img:photos/bee.jpg:w=150&h=150&zc=1}" alt="A bee on a flower">
Expected(an img tag whose src is the img.php thumbnail URL)
ActualA bee on a flower
The canonical pattern: you write the img tag yourself and let {img:} fill the src. In a real view you would use a file-field getter such as {_#FILE____} instead of the literal path. Virtual because the browser renders the tag.
virtual[{img:photos/bee.jpg:w=150&h=150&zc=1}]
Expected[/aaa/img.php?src=/photos/bee.jpg&w=150&h=150&zc=1] (prefix varies by install)
Actual[/aadev/img.php?src=/photos/bee.jpg&w=150&h=150&zc=1&aoe=1]
The common use: build a phpThumb URL and drop it into your own img src. zc=1 crops to exactly 150 by 150. Virtual because the URL path prefix is install-specific - here /aaa/ on this site, /aadev/ when the same view is rendered through view.php - so the exact string is not asserted.
virtual[{img:photos/bee.jpg:w=320}]
Expected[/aaa/img.php?src=/photos/bee.jpg&w=320] (prefix varies by install)
Actual[/aadev/img.php?src=/photos/bee.jpg&w=320]
Give only w and phpThumb scales proportionally. Virtual because the URL path prefix is install-specific. Any phpThumb keys work the same way (q for quality, iar=1 to fit inside a box).
test[{img:photos/bee.jpg}]
Expected[photos/bee.jpg]
Actual[photos/bee.jpg]
With no phpthumb_params there is nothing to resize, so the image path is returned as-is (no img.php wrapper).
test[{img::w=150&h=150}]
Expected[]
Actual[]
An empty first argument yields an empty string - handy so an item with no photo prints nothing instead of a broken tag.
virtual[{img:photos/bee.jpg:w=99&h=99&zc=1:url}]
Expected[/aaa/img.php?src=/photos/bee.jpg&w=99&h=99&zc=1] (prefix varies by install)
Actual[/aadev/img.php?src=/photos/bee.jpg&w=99&h=99&zc=1&aoe=1]
info=url is the same as leaving info empty - it returns the relative URL string. Virtual because the URL path prefix is install-specific.
test[{str_replace:["/aaa/img.php","/aadev/img.php"]:img.php:{img:photos/bee.jpg:w=150&h=150&zc=1}}]
Expected[img.php?src=/photos/bee.jpg&w=150&h=150&zc=1&aoe=1]
Actual[img.php?src=/photos/bee.jpg&w=150&h=150&zc=1&aoe=1]
A deterministic check of what {img:} builds: the install path prefix is stripped (it differs per install), leaving the stable img.php query - src plus your phpThumb params. The src always starts with a slash and the and-signs separate the params. {img:} automatically appends aoe=1 whenever zc plus width and height are all given, to make zoom-crop output deterministic (see AA_Stringexpand_Img::addAoe4ZoomCrop) - that is why aoe=1 appears in the expected query even though the code above never passes it.
virtual{img:photos/bee.jpg:w=150&h=150&zc=1:im:A bee}
Expected(a complete img tag with loading=lazy and title/alt A bee)
ActualA bee
info=im returns a ready img tag (no width/height attributes). param1 becomes the title and alt. Use img instead of im to also include width and height read from the file.
virtual{img:photos/bee.jpg:w=300&h=200&zc=1:picture:A bee}
Expected(a picture element with an avif/webp source and an img fallback)
Actual A bee
info=picture returns a picture element with a modern-format source plus an img fallback - the best choice for content images. Provide w and h in the params so the size is known without loading the file.