Easiest thumb

    It would seem that the typical task is to fill out a catalog of images, prepare several sizes for each and apply arbitrary filters, but I do not find a suitable, simple and convenient tool in modx.

    A simple phpThumb generator implementation based on a single tv and given parameters.

    Call example
    [! thumb? path = `[+ thumb +]` & size = `320x240` & tpl =` thumb`!]

    The original image is set by the template variable [+ thumb +] . Snippet [[thumb]] from the name of the source file (for example image.jpg) and parameters (320x240) forms a single name for the new file (image.320x240.jpg). When accessing the image directory, in accordance with the RewriteRule rule, apache redirects the request to the index.php handler , which splits the file name back into parameters and forms the required image using phpThumb.

    Snippet [[thumb]]
    Accepts one required and two optional parameters
    path path to the image file
    [size] size of the generated image
    [tpl] ofromation pattern

    Depending on the template, the snippet either returns the result issued in accordance with the template, or a string with the final path

    parseChunk ($ tpl, $ params, '[+', '+]');
    return $ output;

    Chunk {{thumb}}
    Accepts one single placeholder [+ path +]

    Query handler index.php
    Accepts the address of the image, breaks the address into arguments and, in accordance with the specified parameters, generates and returns the result.

    setSourceFilename ($ image);
    				$ phpThumb-> setParameter ('w', $ width);
    				$ phpThumb-> setParameter ('h', $ height);
    				$ phpThumb-> setParameter ('zc', '1');
    				$ phpThumb-> setParameter ('q', '100');
    				if ($ phpThumb-> GenerateThumbnail ()) {
    					if ($ phpThumb-> RenderToFile ($ path)) {
    						return header ('Location:'. $ path);
    return header ("HTTP / 1.0 404 Not Found");

    Forwarding rule the apache .htaccess
    Starts the image processing procedure

            Rewriteengine on
            RewriteCond% {REQUEST_FILENAME}! -F
            RewriteCond% {REQUEST_FILENAME}! -D
            RewriteRule ^ (. *) $ Index.php? Path = $ 1 [L, QSA]

    Also popular now: