I use this image resize class for company's logo resize process:
include 'resize-class.php';
function checkImageReq($image){
$size = (int) formatBytes(filesize($image));
list($width, $height) = getimagesize($image);
if($size > 400){
return FALSE;
}
if($width > 300 || $width < 50){
return FALSE;
}
if($height > 300 || $height < 50){
return FALSE;
}
return TRUE;
}
// allows file types
$allowed = array('jpg','png');
// get file type
$extension = pathinfo($_FILES['company_logo']['name'], PATHINFO_EXTENSION);
// I added below methods to create auto resize
$resizeObj = new resize($_FILES['company_logo']['tmp_name']);
$resizeObj -> resizeImage(250, 250, 'auto');
$resizeObj -> saveImage('img.jpg', 1000);
// is there new logo that needs updating
if($_FILES['company_logo']['error'] === 0 && in_array($extension, $allowed)){
$uploaddir = 'images/logo/';
$filename = $mainUser->getUserId().'_'.time().'_'.$_FILES['company_logo']['name'];
$uploadfile = $uploaddir . basename($filename);
if(checkImageReq($_FILES['company_logo']['tmp_name']) && move_uploaded_file($_FILES['company_logo']['tmp_name'], $uploadfile)){
// delete old logo
if(file_exists($uploaddir.$mainUser->getCompanyLogo())){
unlink($uploaddir.$mainUser->getCompanyLogo());
}
$mainUser->setCompanyLogo($filename);
}else{
$image_error = 'Error uploading logo.';
goto end;
}
when I run this script, I get my new EMPTY image created with width and height 250px, I was suspected $resizeObj = new resize($_FILES['company_logo']['tmp_name']);
is never pass the real
image to perform auto resize.
Can someone please advise on how to combine this class to my existing code?
Thanks.