<?php
// relative path where phpThumb is installed -
// modify this if you need to
$strPath = 'assets/snippets/phpThumb';
$strSrc = isset($image) ? $image : '';
$strOptions = isset($options) ? $options : '';
if ( !empty($strSrc) )
{
// config file of phpThumb gets included
require_once($modx->getOption('base_path') . $strPath . '/phpThumb.config.php');
if(!empty($strOptions))
{
// options must begin with a &
if($strOptions[0] != '&') $strOptions = '&' . $strOptions;
}
$strParameter = 'src=' . $strSrc . $strOptions;
// generate hash for security
$strHash= md5($strParameter . @$PHPTHUMB_CONFIG['high_security_password']);
// append hash to query
$strParameter .= '&hash=' . $strHash;
// generate URL and return the result
return $modx->getOption('base_url') . $strPath . '/phpThumb.php' . '?' . $strParameter;
}
else
{
return false;
}
?><img src="[[snpPhpThumb? &image=`/assets/images/mytestimage.jpg` &options=`w=400&h=300`]]" alt="" />
<img src="[[snpPhpThumb? &image=`[[*tvMyTestImage]]` &options=`w=400&h=300`]]" alt="" />
<img src="/modx/assets/snippets/phpThumb_1.7.9/phpThumb.php?src=assets/resources/images/news/P1619[01]_24-05-10kl.jpg&w=664&hash=58966a99b21a322f0ebf9c5a50592a77" title="agsrgsrgsrg" alt="agegsgafaf"/>
"homepages/..../htdocs/modx/assets/snippets/phpThumb_1.7.9/assets/resources/images/news/P1619[01]_24-05-10kl.jpg" does not exist
Needed it today and made a short snippet as a first shot. It’s derived from the phpThumb package made for Evolution (http://modxcms.com/extras/package/341). Be warned: It’s not as comfortable as with phx. Please feel free to enhance - and post it back then.
Usage:
a) Install a vanilla phpThumb (get it here: http://phpthumb.sourceforge.net/#download)
I installed it to /assets/snippets/phpThumb (path can be configured in the first line of the following snippet). Configure phpThumb with "high security" enabled, remember to set "high_security_password" too. Config file of phpThumb is "phpThumb.config.php" (has to be renamed from "phpThumb.config.php.default" first).
b) Snippet - make a new snippet in Revo and call it "snpPhpThumb".
<?php // relative path where phpThumb is installed - // modify this if you need to $strPath = 'assets/snippets/phpThumb'; $strSrc = isset($image) ? $image : ''; $strOptions = isset($options) ? $options : ''; if ( !empty($strSrc) ) { // config file of phpThumb gets included require_once($modx->getOption('base_path') . $strPath . '/phpThumb.config.php'); if(!empty($strOptions)) { // options must begin with a & if($strOptions[0] != '&') $strOptions = '&' . $strOptions; } $strParameter = 'src=' . $strSrc . $strOptions; // generate hash for security $strHash= md5($strParameter . @$PHPTHUMB_CONFIG['high_security_password']); // append hash to query $strParameter .= '&hash=' . $strHash; // generate URL and return the result return $modx->getOption('base_url') . $strPath . '/phpThumb.php' . '?' . $strParameter; } else { return false; } ?>
c) Call of snippet in your resource or template, for example:
<img src="[[snpPhpThumb? &image=`/assets/images/mytestimage.jpg` &options=`w=400&h=300`]]" alt="" />
Or use a TV:
<img src="[[snpPhpThumb? &image=`[[*tvMyTestImage]]` &options=`w=400&h=300`]]" alt="" />
Every option pf phpThumb can be used, see docs or demo (http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php)
global $PHPTHUMB_CONFIG;
require_once($modx->getOption('base_path') . $strPath . '/phpThumb.config.php');
Yeah... you’re right.
I can use the phpThumb connector from domain A on domain B to crop a picture from domain C.
And I believe they are not being cached... can’t find the cached files.
Downloaded and loved it
I just made something yesterday that functions like your original request. I submitted it to the extras repository today, but I doubt it is available yet.
I have attached it to this post so you can give it a try. Let me know how it works for you!
-Jared
UPDATE: Fixed package upload
Depending on where you are using this it could be beneficial to use & instead of & to avoid validation errors. Thank you!
a) Install a vanilla phpThumb (get it here: http://phpthumb.sourceforge.net/#download)
I installed it to /assets/snippets/phpThumb (path can be configured in the first line of the following snippet). Configure phpThumb with "high security" enabled, remember to set "high_security_password" too. Config file of phpThumb is "phpThumb.config.php" (has to be renamed from "phpThumb.config.php.default" first).