сделал правки в коде image.php
пустые поля к картинкам не добавляются. просто изменяются пропорции.
я использую для создания картинок одинаковой ширины, но разных по высоте
public function resize($width = 0, $height = 0) {
if (!$this->info['width'] || !$this->info['height']) {
return;
}
$xpos = 0;
$ypos = 0;
$scale = min($width / $this->info['width'], $height / $this->info['height']);
if ($scale == 1 && $this->info['mime'] != 'image/png') {
return;
}
$new_width = (int)($this->info['width'] * $scale);
$new_height = (int)($this->info['height'] * $scale);
//$xpos = (int)(($width - $new_width) / 2);
//$ypos = (int)(($height - $new_height) / 2);
$xpos = 0;
$ypos = 0;
$image_old = $this->image;
//$this->image = imagecreatetruecolor($width, $height);
// преобразуем, сохранив пропорции
$this->image = imagecreatetruecolor($new_width, $new_height);
if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') {
imagealphablending($this->image, false);
imagesavealpha($this->image, true);
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
imagecolortransparent($this->image, $background);
} else {
$background = imagecolorallocate($this->image, 255, 255, 255);
}
// не будем создавать новый прямоугольник
//imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);
imagedestroy($image_old);
//$this->info['width'] = $width;
// $this->info['height'] = $height;
$this->info['width'] = $new_width;
$this->info['height'] = $new_height;
}