GD缩略图生成器有问题 [英] Having issues with GD thumbnail generator
问题描述
我正在使用PHP生成缩略图.问题是缩略图的宽度和高度设置了我需要的值,并且经常需要拉伸图像.
I'm using PHP to generate thumbnails. The problem is that I have a set width and height the thumbnails need to be and often times the images are stretched.
我想要的是图像保持相同的比例,并且在左侧和左侧仅保留黑色填充物(或任何颜色).适用于高大的图像或顶部和顶部底部显示宽幅图像.
What I'd like is the image to remain at the same proportions and just have black filler (or any color) either on the left & right for tall images or top & bottom for wide images.
这是我当前正在使用的代码:(为便于阅读,对其进行了简要介绍)
Here is the code I'm currently using: (dumbed down a bit for readability)
$temp_image_file = imagecreatefromjpeg("http://www.example.com/image.jpg");
list($width,$height) = getimagesize("http://www.example.com/image.jpg");
$image_file = imagecreatetruecolor(166,103);
imagecopyresampled($image_file,$temp_image_file,0,0,0,0,166,103,$width,$height);
imagejpeg($image_file,"thumbnails/thumbnail.jpg",50);
imagedestroy($temp_image_file);
imagedestroy($image_file);
推荐答案
您需要计算新宽度&保持图像比例的高度.在此页面上查看示例2:
You'll need to calculate the new width & height to keep the image proportionat. Check out example 2 on this page:
http://us3.php.net/imagecopyresampled
这篇关于GD缩略图生成器有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!