Quote from: Bytesource at Mar 21, 2009, 10:16 AM
Hi,
I am looking for a plugin that automatically resamples images after manually resizing them in TinyMCE.
Hi there,
you might have a look at this:
"your_modx_path/manager/media/browser/mcpuk/connectors/php/Commands/Thumbnail.php"
You can easily edit it to have the thumbnail you wish.
/**
* Size of preferred thumbnail
* @int unknown_type
*/
var $preferred_size = 200;
/**
* Color Red
* @int color
*/
var $red = 255;
/**
* Color Green
* @int color
*/
var $green = 255;
/**
* Color Blue
* @int color
*/
var $blue = 239;
...
function resizeImage($img) {
//Get size for thumbnail
$width=imagesx($img); $height=imagesy($img);
if ($width>$height) { $n_height=$height*($this->preferred_size/$width); $n_width=$this->preferred_size; } else { $n_width=$width*($this->preferred_size/$height); $n_height=$this->preferred_size; }
$x=0;$y=0;
if ($n_width<$this->preferred_size) $x=round(($this->preferred_size-$n_width)/2);
if ($n_height<$this->preferred_size) $y=round(($this->preferred_size-$n_height)/2);
$thumb=imagecreatetruecolor($this->preferred_size,$this->preferred_size);
#Background colour fix by:
#Ben Lancaster ([email protected])
$bgcolor = imagecolorallocate($thumb,$this->red, $this->green, $this->blue);
imagefill($thumb, 0, 0, $bgcolor);
if (function_exists("imagecopyresampled")) {
if (!($result=@imagecopyresampled($thumb,$img,$x,$y,0,0,$n_width,$n_height,$width,$height))) {
$result=imagecopyresized($thumb,$img,$x,$y,0,0,$n_width,$n_height,$width,$height);
}
} else {
$result=imagecopyresized($thumb,$img,$x,$y,0,0,$n_width,$n_height,$width,$height);
}
return ($result)?$thumb:false;
}
I wanted to have the background to appear in a more yellow-like color, the size of each .thumb 200x200pixels.
The directory where the thumbs are being stored can be easily changed... No need for an extra snippet/module.
function Thumbnail($fckphp_config,$type,$cwd) {
...
$this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd));
...
}
...
var $cwd;
var $actual_cwd;
var $filename;
...
function run() {
//$mimeIcon=getMimeIcon($mime);
$fullfile=$this->real_cwd.'/'.$this->filename;
$thumbfile=$this->real_cwd.'/.thumb_'.$this->filename;
...
}
Cheers