[! thumb? path = `[+ thumb +]` & size = `320x240` & tpl =` thumb`!]
<? php
if (! empty ($ path)) {
$ size = (empty ($ size))? $ size: '320x240';
$ path = explode ('.', $ path);
array_splice ($ path, -1, 0, $ size);
$ output = $ path = implode ('.', $ path);
if (! empty ($ tpl)) {
$ params ['path'] = $ path;
$ output = $ modx-> parseChunk ($ tpl, $ params, '[+', '+]');
}
}
return $ output;
?> <img src = "[+ path +]">
<? php
if (! empty ($ _ GET ['path'])) {
if (! file_exists ($ path = $ _GET ['path'])) {
$ image = explode ('.', $ path);
$ size = end (array_splice ($ image, -2, 1));
if (in_array ($ size, array ('100x50', '200x100', '300x150'))) {
$ image = implode ('.', $ image);
if (file_exists ($ image)) {
list ($ width, $ height) = explode ('x', $ size);
require ('phpthumb.class.php');
$ phpThumb = new phpThumb ();
$ phpThumb-> 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");
?> <IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond% {REQUEST_FILENAME}! -F
RewriteCond% {REQUEST_FILENAME}! -D
RewriteRule ^ (. *) $ Index.php? Path = $ 1 [L, QSA]
</ IfModule> Source: https://habr.com/ru/post/87184/
All Articles