MODX imgattr - Output Filter for Image Files

Apr 11, 2013

The Skinny

imgattr is an output filter snippet for MODX Revolution that gets attributes from image files. You need to supply it with a valid path to an image file, via a TV or another MODX placeholder.


Where the value of [[*image_tv]] is assets/images/photo.jpg with dimensions of 100px x 50px.

[[*image_tv:imgattr=`filename`]] => photo.jpg
[[*image_tv:imgattr=`filenameNoExt`]] => photo *v.1.0.0-pl1
[[*image_tv:imgattr=`width`]] => 100
[[*image_tv:imgattr=`height`]] => 50
[[*image_tv:imgattr=`dimensions`]] => width="100" height="50"
[[*image_tv:imgattr=`mime`]] => image/jpg

The Phat

Install via Package Management or download from the repo.

MODX is da BOMB!

*UPDATE: imgattr version 2.0.0-pl sports the following improvements:

  • Normalizes for base_url and prepends base_path for reliability
  • Sends errors to log instead of returning them
  • Added toPlaceholder support
  • General code improvements

A big shout-out to Mike @netProphET for his code betterment and testing goodness!