================================== ========== version 2.1 =========== ================================== -------------------------------- What's this?? -------------------------------- As many people with low skills have problems to resize pictures they would like to upload to a CMSimple Website, I decided to write a few lines of php code - maybe as a tiny kind of extension for CMSimple. This is not a very difficult script, but it could save you a free afternoon if you don't need to program such code while it is already existing. What it does: - A combocox to choose the size in the image upload form is created. - The combobox contains some size 'definitions' set by the webmaster in the config script - Furthermore the user can set a new name for the uploaded file Only jpg pictures can be resized. Only jpg, gif and png pictures can be renamed. If a picture is wider than the idealwidth, it'll be resized to this ideal width. If a picture is not too wide but too high, the resize-factor is calculated to fit the ideal height. You don't need to type '.jpg' or '.gif' or something like that into the textfield. Don't forget to translate the messages into your language. -------------------------------- System Requirements -------------------------------- Of course: - A working CMSimple system (v2.3 or v2.4) http://www.cmsimple.dk/ and in order to work on images: - GD library 2.0 or later (please check phpinfo(); and make sure it is installed) It is available at http://www.boutell.com/gd/ -------------------------------- How to install -------------------------------- ####################### Step 1 - Configuration ####################### Insert the following three lines in config.php (for example after the existing $cf['images']['maxsize']="1500000"; ) $cf['resize_modes']['Name of the Definition']="idealwidth idealheight quality"; for example: $cf['resize_modes']['Thumbnail']="100 100 46"; $cf['resize_modes']['Medium_Size']="200 200 54"; $cf['resize_modes']['Normal_Size']="300 300 58"; $cf['resize_modes']['As_big_as_possible']="550 400 58"; That allows you to determine the quality of the resized jpg-images in the configuration backend of cmsimple. You can add as many lines as you want! (Even zero) Please use underscores _ instead of spaces ' ' ! ###################### Step 2 - Including Addon Script ##################### Search for if($f=='images'||$f=='downloads'){ put this AFTER it. include 'photoresize.php'; ####################### Step 3 - Resizing ####################### ************* CMSimple v2.3 and v2.4 ************* Search for this piece of code in cms.php $o.='

'.ucfirst($tx['filetype']['file']).' '.$name.' '.$tx['result']['uploaded'].'

'; and insert this IN FRONT of it {if($resize_mode != "none" && array_key_exists($resize_mode, $cf['resize_modes'])){$mode = explode(' ',$cf['resize_modes'][$resize_mode]);$imgresizefilename = $pth['folder'][$f].$name;addon_resize($imgresizefilename, $mode[0],$mode[1],$mode[2]);} and a single } BEHIND it. The code now looks like this: {if($resize_mode != "none" && array_key_exists($resize_mode, $cf['resize_modes'])){$mode = explode(' ',$cf['resize_modes'][$resize_mode]);$imgresizefilename = $pth['folder'][$f].$name;addon_resize($imgresizefilename, $mode[0],$mode[1],$mode[2]);} $o.='

'.ucfirst($tx['filetype']['file']).' '.$name.' '.$tx['result']['uploaded'].'

';} ######################## Step 4 - Renaming ######################## ************* CMSimple v2.3 and v2.4 ************* In cms.php Search for $name=im($f,'name'); and put this BEHIND it: $name=addon_rename($name); ######################### Step 5 - Checkbox And Textfield ######################### ************* CMSimple v2.3 ************* Still in cms.php look for and insert this text IN FRONT of it: '.($f=='images'?addon_get_form():'').' ************* CMSimple v2.4 ************* In cms.php look for .tag('input type="submit" class="submit" value="'.ucfirst($tx['action']['upload']).'"') and put this IN FRONT of it .($f=='images'?addon_get_form():'') ######################## Step 6 - Addon Script ######################## Create a new file "photoresize.php" in the cmsimple/ (where cms.php is) directory with this content: "; $info = getimagesize($filename1); if($info[2] == 2)//Yes, it is JPG { $idealwidth = $width; $idealheight = $height; $img1 = imagecreatefromjpeg($filename1); $oldw = $info[0]; $oldh = $info[1]; $o.= "old size: width = $oldw px; height = $oldh px
"; if($oldw > $idealwidth){ $factor = $idealwidth / $oldw; }elseif($oldh > $idealheight){ $factor = $idealheight / $oldh; }else{ $factor = 1; } if($factor!=1){ $neww = ceil($oldw * $factor); $newh = ceil($oldh * $factor); $o.= "factor: $factor; quality: $quality %
new size: width = $neww px; height = $newh px
"; $img2 = imagecreatetruecolor($neww, $newh); imagecopyresampled($img2,$img1,0,0,0, 0,$neww,$newh,$oldw,$oldh); imagejpeg($img2,$filename2,$quality);//save imagedestroy($img2); } imagedestroy($img1); }else{ $o.="$filename1 is not JPEG! I cannot resize it."; } $o.="

"; } function addon_get_form() { global $cf; $ret='
Choose the size:
Save as (new filename):
'; return $ret; } ?> ############################ Tips ############################ If you want ALL Pics to be resized, remove out of photoresize.php. Then every image is resized in the way the first definition describes. ---------------------------------- Author ---------------------------------- This document is written by Stefan Großhauser netscraper{[_at_}]web.de Thanks to Peter Harteq for the great CMSimple system! If you like it, feel free to send me a feedback email or to put a link to: http://www.djk-rohr.de/ or http://www.eks-pohe.de/