<![CDATA[ How to resample images? - My Forums]]> https://forums.modx.com/thread/?thread=45692 <![CDATA[Re: How to resample images?]]> https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264421 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]]>
Katzenfutter Apr 17, 2009, 05:52 AM https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264421
<![CDATA[Re: How to resample images?]]> https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264420
Thanks for your advice. I found the current version of DirektResize on Google Code: http://code.google.com/p/directresize-modx/updates/list
An automatic translation of the Russian readme file can be found here: http://modx.metaller.ru/assets/plugins/directresize/docs/readme_ru.html" target="_blank" rel="nofollow">http://translate.google.com/translate?hl=ru&sl=ru&tl=en&u=http://modx.metaller.ru/assets/plugins/directresize/docs/readme_ru.html]]>
Bytesource Mar 22, 2009, 04:36 AM https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264420
<![CDATA[Re: How to resample images?]]> https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264419 I can’t see it in the new repository bt the forum thread is here.]]> bunk58 Mar 21, 2009, 06:07 AM https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264419 <![CDATA[How to resample images?]]> https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264418
I am looking for a plugin that automatically resamples images after manually resizing them in TinyMCE. The original image should be kept untouched while a resampled copy is stored in another folder. Up to know the size of a resized image does not change but only gets scaled, as can be seen in the image properties: Image Dimensions: 146px × 269px (scaled to 105px × 188px)

I would like to know if there is a plugin in Modx or TinyMCE to achieve this goal? This feature would save me a lot bandwidth as users often upload very large pictures.

Looking forward to your reply!]]>
Bytesource Mar 21, 2009, 05:16 AM https://forums.modx.com/thread/45692/how-to-resample-images#dis-post-264418