/ Published in: PHP
Resize and image to fit a predetermined canvas size
Expand |
Embed | Plain Text
// 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']; $src = imagecreatefromjpeg($uploadedfile); }else if($extension=="png"){ $uploadedfile = $_FILES[$formname]['tmp_name']; $src = imagecreatefrompng($uploadedfile); }else{ $src = imagecreatefromgif($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; } $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
You need to login to post a comment.
