Javascript 用于自动调整图像的Php代码
我正在使用一个php代码来制作缩略图并进行拟合。我附上了一张我想要的照片。我使用的脚本是拉伸图像。这些脚本不适合图像宽度和高度 谁能帮我整理一下这个问题。Javascript 用于自动调整图像的Php代码,javascript,php,image,thumbnails,Javascript,Php,Image,Thumbnails,我正在使用一个php代码来制作缩略图并进行拟合。我附上了一张我想要的照片。我使用的脚本是拉伸图像。这些脚本不适合图像宽度和高度 谁能帮我整理一下这个问题。 我不知道你的代码有什么问题,因为你还没有发布,但这里有一个方便的函数,我用来创建缩略图 function make_thumb($src, $dest, $desired_width) { /* read the source image */ $source_image = imagecreatefromjpeg($src
我不知道你的代码有什么问题,因为你还没有发布,但这里有一个方便的函数,我用来创建缩略图
function make_thumb($src, $dest, $desired_width) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image, $dest);
}
$src:指向您的图像的Url$des:您希望缩略图位于的位置
$width:缩略图的宽度