Webgui: ongoing development
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
require 'globals.inc';
|
||||
require 'lib/gpc.inc';
|
||||
require 'lib/fileutils.inc';
|
||||
|
||||
$pagetitle = _('Equipment');
|
||||
@@ -135,6 +136,44 @@ switch ($submit = form_get_action()) {
|
||||
if ($nerr > 0) {
|
||||
break;
|
||||
}
|
||||
// scale down if dimensions exceed limits
|
||||
$img_maxx= $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=20")->fetchColumn();
|
||||
$img_maxy= $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=21")->fetchColumn();
|
||||
[$width, $height] = getimagesize($file_tmp);
|
||||
$factor = min($img_maxx / $width, $img_maxy / $height);
|
||||
if ($factor < 1) {
|
||||
$width = (int)($width * $factor);
|
||||
$height = (int)($height * $factor);
|
||||
$g_message->add(sprintf(_('Image sacled down to %dx%d'), $width, $height));
|
||||
if ($file_mimetype == 'image/jpeg') {
|
||||
$orig = imagecreatefromjpeg($file_tmp);
|
||||
$scaled = imagescale($orig, (int)($width * $factor), (int)($height * $factor), IMG_BICUBIC);
|
||||
imagejpeg($scaled, $file_tmp, 85);
|
||||
} else if ($file_mimetype == 'image/png') {
|
||||
$orig = imagecreatefrompng($file_tmp);
|
||||
if (!$orig) {
|
||||
$g_error->Add("imagecreatefrompng failed");
|
||||
break;
|
||||
}
|
||||
$scaled = imagescale($orig, (int)($width * $factor), (int)($height * $factor), IMG_BICUBIC);
|
||||
if (!$scaled) {
|
||||
$g_error->Add("imagescale failed");
|
||||
break;
|
||||
}
|
||||
imagepng($scaled, $file_tmp, 9);
|
||||
} else {
|
||||
$g_error->Add(sprintf(_('Internal error: Unknown mimetype %s!'), $file_mimetype));
|
||||
break;
|
||||
}
|
||||
$file_size = filesize($file_tmp);
|
||||
}
|
||||
|
||||
// check if storage limit is exceeded
|
||||
if (dir_get_size($g_doc_basepath) + $file_size > $g_storage_limit * 1024 * 1024) {
|
||||
$g_error->Add(_('Storage limit exceeded. Image not uploaded!'));
|
||||
break;
|
||||
}
|
||||
|
||||
$file_hash = md5_file($file_tmp);
|
||||
$file_timestamp = date('Y-m-d H:i:s', filemtime($file_tmp));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user