Revision: 47483
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 9, 2011 01:03 by flatearthcomms
Initial Code
// NOW UPLOAD THE LOGO $formname = 'CompanyLogo'; if(isset($_FILES[$formname]['name'])){ $name = stripslashes($_FILES[$formname]['name']); if ($name!=""){ $name = str_replace(" ", "_" , $name) ; //if(move_uploaded_file($_FILES[$formname]['tmp_name'], "../images_cms/{$name}")){ $extension = getExtension($name); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo ' Unknown Image extension '; $errors=1; }else{ $size=filesize($_FILES[$formname]['tmp_name']); //if ($size > MAX_SIZE*1024){ //echo "You have exceeded the size limit"; //$errors=1; //} if($extension=="jpg" || $extension=="jpeg" ){ $uploadedfile = $_FILES[$formname]['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); }else if($extension=="png"){ $uploadedfile = $_FILES[$formname]['tmp_name']; $src = imagecreatefrompng($uploadedfile); }else{ $src = imagecreatefromgif($uploadedfile); } list($width,$height)=getimagesize($uploadedfile); $canvasW = 230 ; $canvasH = 78 ; $newwidth = $canvasW; $newheight = ($height/$width)*$newwidth; // IF THE PROPOTIONS ARE WRONG if ($newheight > $canvasH) { $newheight = $canvasH; $newwidth=($width/$height)*$newheight; } $offsetY = intval( ($canvasH-$newheight)/2 ); $tmp=imagecreatetruecolor($canvasW,$canvasH); $white=imagecolorallocate($tmp,255,255,255); imagefilledrectangle($tmp,0,0,$canvasW,$canvasH,$white); // imagecopyresampled ( resource $dst_image , resource $src_image , // int $dst_x , int $dst_y , // int $src_x , int $src_y , // int $dst_w , int $dst_h , int $src_w , int $src_h ) imagecopyresampled($tmp,$src, 0,$offsetY, 0,0, $newwidth,$newheight, $width,$height); $imgPath = "../images_cms/{$name}" ; imagejpeg($tmp,$imgPath,100); imagedestroy($src); imagedestroy($tmp); $sql_cmpy=" UPDATE `cms_companies` SET `CompanyLogo`='$name' WHERE `companyID`='$companyID' "; $result_cmpy=doSQL($sql_cmpy); } // END if $extention } // END if $name } // END LOGO
Initial URL
Initial Description
Resize and image to fit a predetermined canvas size
Initial Title
File upload: Resize image and reposition on new canvas
Initial Tags
php, resize, image, file
Initial Language
PHP