А всего-то надо внести небольшие изменения в файл …/includes/functions_upload.php вашего форума.
1. Найдите в нем следующие строки:
phpbb_chmod($this->destination_file, $chmod);
}
Добавьте после них: $this->resize();
2. Найдите далее:
return true;
}
Добавьте после:
Код: Выделить всё
function resize(){
global $config;
if (!empty($config['img_max_width']) && !empty($config['img_max_height'])){
$max_width = $config['img_max_width'];
$max_height = $config['img_max_height'];
}else{
$max_width = 800;
$max_height = 600;
}
if (!empty($max_width) && !empty($max_height)){
$filename = $this->destination_file;
if ($image_info = @getimagesize($filename)){
$image_width = $image_info[0];
$image_height = $image_info[1];
$image_type = $image_info[2];
if (($image_width > $max_width) || ($image_height > $max_height)){
$ratio = $image_width / $image_height;
$w_scale = $max_width / $image_width;
$h_scale = $max_height / $image_height;
if ($w_scale <= $h_scale){
$width = $max_width;
$height = round($width / $ratio);
if ($height > $max_height) $height = $max_height;
}else{
$height = $max_height;
$width = round($height * $ratio);
if ($width > $max_width) $width = $max_width;
}
if ($image_type == IMAGETYPE_JPEG){
$image = imagecreatefromjpeg($filename);
}elseif ($image_type == IMAGETYPE_GIF){
$image = imagecreatefromgif($filename);
}elseif ($image_type == IMAGETYPE_PNG){
$image = imagecreatefrompng($filename);
}else{
return;
}
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
$image = $new_image;
if ($image_type == IMAGETYPE_JPEG){
imagejpeg($image, $filename, 80);
}elseif ($image_type == IMAGETYPE_GIF){
imagegif($image, $filename);
}elseif ($image_type == IMAGETYPE_PNG){
imagepng($image, $filename);
}
}
}
}
}