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

Description

Builds a phpThumb image URL from an image path or URL plus resize parameters. By default (no info) it returns just the URL string, which you place inside your own img src attribute - this is 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. 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; url and rawurl return the relative or absolute URL; width, height, mime and imgtype return metadata read from the actual image (this loads the file, so it is slower and only works for a reachable image). An empty image argument yields an empty string. The URL points at this install img.php handler, so its path prefix is install-specific (for example /aaa here, /aadev through view.php).

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 wrapped into the img.php URL (the file is not loaded); the metadata modes (width, height, mime) do load it. 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 relative img.php URL string (the default, for use inside your own img src). rawurl returns 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 metadata read from the actual image file (slower; needs a reachable image). 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]
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]
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]
Actual[img.php?src=/photos/bee.jpg&w=150&h=150&zc=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.
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.