do not scale user image if too small, allow images up to 300px height

This commit is contained in:
Uwe Steinmann 2023-09-27 11:30:02 +02:00
parent 4cb589b0ed
commit 929c93fdb9

View File

@ -485,30 +485,27 @@ else UI::exitError(getMLText("admin_tools"),getMLText("unknown_command"));
function resizeImage($imageFile) {
// Not perfect. Creates a new image even if the old one is acceptable,
// and the output quality is low. Now uses the function imagecreatetruecolor(),
// though, so at least the pictures are in colour.
// read original image
$origImg = imagecreatefromjpeg($imageFile);
$width = imagesx($origImg);
$height = imagesy($origImg);
// Create thumbnail in memory
$newHeight = 150;
$newHeight = 300;
$newWidth = ($width/$height) * $newHeight;
$newImg = imagecreatetruecolor($newWidth, $newHeight);
// resize
imagecopyresized($newImg, $origImg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// save to file
imagejpeg($newImg, $imageFile);
// Clean up
/* Do not scale images which are already small enough */
if($newWidth < $width || $newHeight < $height) {
$newImg = imagecreatetruecolor($newWidth, $newHeight);
// resize
imagecopyresized($newImg, $origImg, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
// save to file
imagejpeg($newImg, $imageFile);
// Clean up
imagedestroy($newImg);
}
imagedestroy($origImg);
imagedestroy($newImg);
return true;
}
header("Location:../out/out.UsrMgr.php?userid=".$userid);
?>