[英]Php creating image thumb with fixed width and height
Guys i know that this question is asked before but its not the same because i have tried others answers and nothing worked as I want. 伙计们,我知道这个问题是以前问过的,但它不是一样的,因为我尝试了其他答案,但没有按我希望的那样工作。
I want to create thumbnail image using php and the thumbnail width="265px" and height="125px" and here is my code : 我想使用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);
I am not very sure about my comments but i just wrote them just in case 我对我的评论不是很确定,但我只是写了些以防万一
I think it need someone that is good in maths 我认为它需要一个数学上好的人
Thanks and happy new year 谢谢,新年快乐
No math required.. 不需要数学。
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]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.