Contact

If you like a new Web or Desktop
application, update a existing one
or add new modifications. Your at
the right place and hit the
hire me button

Follow

If your intersted you can follow
me on Twitter by clicking here

Web and Apps Building Refernce World Wild Web UNIX Apps AND Tips Programming languages

Fckeditor image resize

Fckeditor (Html text editor) v-2.6.4 does not have automatic image resizing feature on upload or at least i don't know :( whether this editor has this feature. So to be able to resize picture on upload via fckeditor i bring some changes on "commands.php" file of fckeditor files. This file located on '\editor\filemanager\connectors\php' of the fckeditor folder. Open this file and

1. go to line # 219. It looks like

  1. move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;  

move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;

This line is under the function 'FileUpload'

2. Now change the line to
  1. if($sExtension == 'jpg' || $sExtension == 'jpeg' || $sExtension == 'gif' )  
  2. {  
  3.   $uploadedfile = $_FILES['NewFile']['tmp_name'];  
  4.   
  5.   // Create an Image from it so we can do the resize  
  6.   $src = imagecreatefromjpeg($uploadedfile);  
  7.         
  8.   // Capture the original size of the uploaded image  
  9.   list($width,$height)=getimagesize($uploadedfile);  
  10.        
  11.   // For my purposes, I have resized the image to be  
  12.   // 300 pixels wide, and maintain the original aspect  
  13.   // ratio. This prevents the image from being "stretched"  
  14.   // or "squashed". If you prefer some max width other than  
  15.   // 300, simply change the $newwidth variable  
  16.   $newwidth=300;  
  17.   $newheight=($height/$width)*$newwidth;  
  18.   $tmp=imagecreatetruecolor($newwidth,$newheight);  
  19.         
  20.   // this line actually does the image resizing, copying from the original  
  21.   // image into the $tmp image  
  22.   imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);  
  23.         
  24.   // now write the resized image to disk. I have assumed that you want the  
  25.   // resized, uploaded image file to reside in the ./images subdirectory.  
  26.   $filename = $_FILES['NewFile']['tmp_name'];  
  27.   imagejpeg($tmp,$filename,100);  
  28.   move_uploaded_file( $filename$sFilePath ) ;  
  29.   imagedestroy($src);  
  30.   imagedestroy($tmp);  
  31. }  
  32. else  
  33. {  
  34.   move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;  
  35. }  

if($sExtension == 'jpg' || $sExtension == 'jpeg' || $sExtension == 'gif' )
{
  $uploadedfile = $_FILES['NewFile']['tmp_name'];

  // Create an Image from it so we can do the resize
  $src = imagecreatefromjpeg($uploadedfile);
      
  // Capture the original size of the uploaded image
  list($width,$height)=getimagesize($uploadedfile);
     
  // For my purposes, I have resized the image to be
  // 300 pixels wide, and maintain the original aspect
  // ratio. This prevents the image from being "stretched"
  // or "squashed". If you prefer some max width other than
  // 300, simply change the $newwidth variable
  $newwidth=300;
  $newheight=($height/$width)*$newwidth;
  $tmp=imagecreatetruecolor($newwidth,$newheight);
      
  // this line actually does the image resizing, copying from the original
  // image into the $tmp image
  imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
      
  // now write the resized image to disk. I have assumed that you want the
  // resized, uploaded image file to reside in the ./images subdirectory.
  $filename = $_FILES['NewFile']['tmp_name'];
  imagejpeg($tmp,$filename,100);
  move_uploaded_file( $filename, $sFilePath ) ;
  imagedestroy($src);
  imagedestroy($tmp);
}
else
{
  move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
}