ImageInfo is a Snippet for MODX Evolution.
With ImageInfo you can get image information and output the resulting data, for example you can get the image file size in KB or MB, the image width and height in pixels, and show a text for the average image dimensions: XLarge, Large, Medium, Small, XSmall.
Snippet developed by: Lorenzo Stanco.
1. Installation
To install ImageInfo Snippet go to "Elements > Manage Elements > Snippets > New Snippet" and write as follows:
Snippet Name: imageinfo
Snippet Description: Get Image Information
Snippet code (php):
<?php
/**
* Snippet Name: imageinfo
* Short Desc: Get Image Information
* Author: Lorenzo Stanco <www.lorenzostanco.com>
* Version: 1.0.0
* Last Edited: 21-04-2011
*/
// ---------------------------------------------------
// Config
// ---------------------------------------------------
// $filename: [string] name of original file, default directory: 'assets/images/'
// $type: [string] one of resolution|resolutionx|resolutiony|resolutionlabel|filesize
//-----------------------------------------------------
//
//
// PARAMETERS
// resolution: 4000 x 3000 px
// resolutionx: 4000
// resolutiony: 3000
// resolutionlabel: XLarge
// filesize: 5,45 MB
//
//
// EXAMPLES
// [[imageinfo? &filename=`[*img1*]` &type=`resolution`]]
// [[imageinfo? &filename=`[*img1*]` &type=`resolutionlabel`]]
// [[imageinfo? &filename=`[*img1*]` &type=`resolutionx`]]
// [[imageinfo? &filename=`[*img1*]` &type=`resolutiony`]]
// [[imageinfo? &filename=`[*img1*]` &type=`filesize`]]
//-----------------------------------------------------
$pathImg = ((substr($filename, 0, 7) == 'http://') ? $filename : 'assets/images/' . str_replace('assets/images/', '', $filename));
if ($type != 'filesize') {
$imageinfo = getimagesize($pathImg);
$x = $imageinfo[0];
$y = $imageinfo[1];
}
switch ($type) {
case 'filesize':
$val = filesize($pathImg);
$round = 2;
$unit = array('','K','M','G','T','P','E','Z','Y');
do { $val /= 1024; array_shift($unit); } while ($val >= 1000);
return str_replace('.', ',', sprintf('%.' . intval($round) . 'f', $val)) . ' ' . array_shift($unit) . 'B';
case 'resolution':
return $x . ' x ' . $y . ' px';
case 'resolutionx':
return $x;
case 'resolutiony':
return $y;
case 'resolutionlabel':
$sqp = $x * $y;
if ($sqp >= 12000000) return 'XLarge';
if ($sqp >= 4000000) return 'Large';
if ($sqp >= 1800000) return 'Medium';
if ($sqp >= 450000) return 'Small';
return 'XSmall';
}
return '';
?>
2. Parameter &filename
This parameter is required. Filename lets you specify the path of the image.
You can use it like this: &filename=`[*img1*]`.
3. Parameter &type="resolution"
This parameter get the image resolution, for example: 4000 x 3000 px.
ImageInfo Call example:
[[imageinfo? &filename=`[*img1*]` &type=`resolution`]]
4. Parameter &type="resolutionlabel"
This parameter get the image resolution and, depending on the image dimensions, it displays one of these: XLarge, Large, Medium, Small, XSmall.
ImageInfo Call example:
[[imageinfo? &filename=`[*img1*]` &type=`resolutionlabel`]]
5. Parameter &type="resolutionx"
This parameter get the image width, for example: 4000.
ImageInfo Call example:
[[imageinfo? &filename=`[*img1*]` &type=`resolutionx`]]
6. Parameter &type="resolutiony"
This parameter get the image height, for example: 3000.
ImageInfo Call example:
[[imageinfo? &filename=`[*img1*]` &type=`resolutiony`]]
7. Parameter &type="filesize"
This parameter get the image file size, for example: 350,20 KB.
ImageInfo Call example:
[[imageinfo? &filename=`[*img1*]` &type=`filesize`]]
8. Example
Here's an example of what you can do with this Snippet:

