Php 创建固定宽度和高度的图像缩略图

Php creating image thumb with fixed width and height

伙计们,我知道以前有人问过这个问题,但它不一样,因为我已经尝试过其他答案,但没有任何效果。

我想使用 php 和缩略图 width="265px"height="125px" 创建缩略图] 这是我的代码:

$image_width = $imageSize[0];
$image_height = $imageSize[1];

$new_size = ($image_width + $image_height) / ($image_width * ($image_height / 45));         //this will set any image to 125*70 which is a good thumbnail

$new_width = $image_width * $new_size;
$new_height = $image_height * $new_size;

if($ext == "gif"){ 
    $old_image = imagecreatefromgif($real_image_path);
}else if($ext =="png"){ 
    $old_image = imagecreatefrompng($real_image_path);
}else{ 
    $old_image = imagecreatefromjpeg($real_image_path);
}

$new_image = imagecreatetruecolor($new_width, $new_height);                                                     //creating new image with a new color for quality

imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);

我不太确定我的评论,但我只是写了它们以防万一

我觉得需要数学好的人

谢谢,新年快乐

不需要数学..

if($ext == "gif"){ 
    $old_image = imagecreatefromgif($real_image_path);
}else if($ext =="png"){ 
    $old_image = imagecreatefrompng($real_image_path);
}else{ 
    $old_image = imagecreatefromjpeg($real_image_path);
}
$data = getimagesize($real_image_path);

$height = 125;
$width = 265;
$thumb = imagecreatetruecolor($width, $height);
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
imagecopyresampled($thumb, $old_image, 0, 0, 0, 0, $width, $height, $data[0], $data[1]);