Skip to content

Instantly share code, notes, and snippets.

@dnikonov
Created July 14, 2021 05:28
Show Gist options
  • Save dnikonov/e759d7a2a3ccc1c022589b9e185dc08c to your computer and use it in GitHub Desktop.
Save dnikonov/e759d7a2a3ccc1c022589b9e185dc08c to your computer and use it in GitHub Desktop.
// ресайз загружаемых изображений
if (!function_exists('resizeUploadedImage')) {
/**
* resizeUploadedImage уменьшение изображения
* @param [file] $file временный файл
*/
function resizeUploadedImage(&$file, $w=2000, $h=2000){
if (!empty($file["name"])) {
list($width, $height) = getimagesize($file["tmp_name"]);
if ($width > $w || $height > $h) {
CFile::ResizeImage($file, array("width" => $w, "height" => $h), BX_RESIZE_IMAGE_PROPORTIONAL_ALT);
}
} elseif (!empty($file["VALUE"]["name"])) {
list($width, $height) = getimagesize($file["VALUE"]["tmp_name"]);
if ($width > $w || $height > $h) {
CFile::ResizeImage($file["VALUE"], array("width" => $w, "height" => $h), BX_RESIZE_IMAGE_PROPORTIONAL_ALT);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment