/ Published in: PHP
Resize and image to fit a predetermined canvas size
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// NOW UPLOAD THE LOGO $formname = 'CompanyLogo'; if ($name!=""){ //if(move_uploaded_file($_FILES[$formname]['tmp_name'], "../images_cms/{$name}")){ $extension = getExtension($name); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo ' Unknown Image extension '; $errors=1; }else{ //if ($size > MAX_SIZE*1024){ //echo "You have exceeded the size limit"; //$errors=1; //} if($extension=="jpg" || $extension=="jpeg" ){ $uploadedfile = $_FILES[$formname]['tmp_name']; }else if($extension=="png"){ $uploadedfile = $_FILES[$formname]['tmp_name']; }else{ } $canvasW = 230 ; $canvasH = 78 ; $newwidth = $canvasW; $newheight = ($height/$width)*$newwidth; // IF THE PROPOTIONS ARE WRONG if ($newheight > $canvasH) { $newheight = $canvasH; $newwidth=($width/$height)*$newheight; } // 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 ) 0,$offsetY, 0,0, $newwidth,$newheight, $width,$height); $imgPath = "../images_cms/{$name}" ; $sql_cmpy=" UPDATE `cms_companies` SET `CompanyLogo`='$name' WHERE `companyID`='$companyID' "; $result_cmpy=doSQL($sql_cmpy); } // END if $extention } // END if $name } // END LOGO