Вы можете использовать следующий код для создания миниатюры изображения без изменения соотношения сторон исходного изображения. А здесь $ img - это путь к изображению, где хранится исходное изображение.
$sourceAppImgPath = $this->images->absPath($img);
$file_dimensions = getimagesize($sourceAppImgPath);
$ImageType = strtolower($file_dimensions['mime']);
switch(strtolower($ImageType))
{
case 'image/png':
$image = imagecreatefrompng($sourceAppImgPath);
break;
case 'image/gif':
$image = imagecreatefromgif($sourceAppImgPath);
break;
case 'image/jpeg':
$image = imagecreatefromjpeg($sourceAppImgPath);
break;
default:
return false; //output error
}
$origWidth = imagesx($image);
$origHeight = imagesy($image);
$maxWidth = 300;
$maxHeight =300;
if ($maxWidth == 0)
$maxWidth = $origWidth;
if ($maxHeight == 0)
$maxHeight = $origHeight;
$widthRatio = $maxWidth / $origWidth;
$heightRatio = $maxHeight / $origHeight;
$ratio = min($widthRatio, $heightRatio);
$thumb_width = (int)$origWidth * $ratio;
$thumb_height = (int)$origHeight * $ratio;