如何在PHP开发中生成图像的缩略图
来源:爱站网时间:2020-12-15编辑:网友分享
图像的宽度和高度程序员通常可以进行设置,而图像的大小不改变,也不会影响到图像的像素,下面爱站技术频道小编为大家整理的如何在PHP开发中生成图像的缩略图,需要的朋友可以参考下面的介绍。
图像的宽度和高度程序员通常可以进行设置,而图像的大小不改变,也不会影响到图像的像素,下面爱站技术频道小编为大家整理的如何在PHP开发中生成图像的缩略图,需要的朋友可以参考下面的介绍。
具体如下:
这里需要用到GD2 library
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 */
imagecopyresized($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, 83);
}
如何在PHP开发中生成图像的缩略图的内容爱站技术频道小编就分享到这里,感兴趣的小伙伴可以来js.aizhan.com试试看。
