我将此图像调整大小类用于公司的徽标大小调整过程:
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;
}
当我运行这个脚本时,我得到了宽度和高度为 250 像素的新EMPTY$resizeObj = new resize($_FILES['company_logo']['tmp_name']);
图像,我怀疑它永远不会通过real
图像来执行自动调整大小。
有人可以建议如何将此类与我现有的代码结合起来吗?
谢谢。