MODX Evolution Snippet: Advthumbs, thumbnails generator

Post by Microcipcip, 07/08/2011, 4. Category: MODX Evolution

Advthumbs is a Snippet for MODX Evolution which generates thumbnails on the fly.

Snippet developed by: Lorenzo Stanco.

Download Advthumbs
Demo Advthumbs (Lightbox Gallery)

1. Installation

To install Advthumbs Snippet, follow these steps:

Extract Advthumbs on "sitename/assets/snippets", then go to  "Elements > Manage Elements > Snippets > New Snippet":
Snippet Name: advthumbs.
Snippet Description: Thumbnails Generator.
Snippet code (php): copy the content from "snippet.advthumbs.txt". Save and close.

2. Usage

Examples of Advthumbs usage:

<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resize`]]" alt="[*pagetitle*]" />
<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`crop`]]" alt="[*pagetitle*]" />
<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resizecrop`]]" alt="[*pagetitle*]" />
<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resizeblack`]]" alt="[*pagetitle*]" />
<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resizeblack` &watermark=`1`]]" alt="[*pagetitle*]" />

3. Parameter &filename

This parameter is required. Filename lets you specify the path of the image.
You can use it like this: &filename=`[*img1*]`.

4. Parameter &newxsize, &newysize

These parameters are required. Newxsize and Newysize let you specify the image dimensions.
You can use them like this: &newxsize=`250` &newysize=`400`.

5. Parameter &method=`resize`

This parameter resizes the image until it fits into the specified dimensions, without keeping the image proportions.
Advthumbs Call example:

<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resize`]]" alt="[*pagetitle*]" />

Advthumbs, thumbnails generator

6. Parameter &method=`crop`

This parameter crops the image until it fits the specified dimensions. Basically this parameter displays the center of the image, the rest of the image is cropped out.
Advthumbs Call example:

<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`crop`]]" alt="[*pagetitle*]" />

Advthumbs, thumbnails generator

7. Parameter &method=`resizecrop`

This parameter crops the image and resize it until it fits the specified dimensions, it keeps the image proportions and it center the image exactly in the middle.
Advthumbs Call example:

<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resizecrop`]]" alt="[*pagetitle*]" />

Advthumbs, thumbnails generator

8. Parameter &method=`resizeblack`

This parameter resizes the image and keeps the image proportions, the rest of the image is filled in with black (by default). To change the default color, open "advthumbs/class.image.php" and modify line 188, for example you can change from black to white in this way: 0x00, 0x00, 0x00 -> 0xFF, 0xFF, 0xFF.
Advthumbs Call example:

<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resizeblack`]]" alt="[*pagetitle*]" />

Advthumbs, thumbnails generator

9. Parameter &watermark=`1`

This parameter, if set to true, adds a watermark in the center of the image. By default, the watermark parameter takes the image path from advthumbs/watermark.png. You can change the path from line 61 in the snippet file.
Advthumbs Call example:

<img src="[[advthumbs? &filename=`[*img1*]` &newxsize=`200` &newysize=`200` &method=`resize` &watermark=`1`]]" alt="[*pagetitle*]" />

Advthumbs, thumbnails generator

10. Conclusion

What I think work best is: &method=`resizecrop`, because it keeps the right proportions and it cuts the image in the way I want it to be.

Write a comment

#

whoo

on 09/08/2011, at 09:17:14
Hi there,

great, thanks for the tutorial! do those images get cached / created on the fly and stored somewhere?

thanks
#
on 09/08/2011, at 12:18:22
No they're not cached. That's a feature for the next release.
#

whoo

on 10/08/2011, at 09:43:56
great! thanks :)
#
on 31/08/2011, at 14:14:15
Ok, now the Snippet supports a basic cache system.