3 回答
TA贡献1803条经验 获得超6个赞
我猜您已经知道了这一点。但是我看到您将图像存储为“ longblobs”,这使我认为您正在存储图片的整个二进制内容。
我希望您已经意识到,仅将文件名存储在数据库中,然后使用该信息将图片从“上传”文件夹或类似文件中抓取,将更加有意义。
提示-不要保存文件路径..仅保存文件名..根据需要在代码中添加路径信息。这样一来,您便拥有了最大的自由度。如果需要更改文件夹结构,则可以在代码中完成,而无需更改数据库记录。
TA贡献1784条经验 获得超8个赞
您可以使用最简单的方法
<?php
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="1494684586337H.jpg";
$dest="new.jpg";
$desired_width="200";
make_thumb($src, $dest, $desired_width);
?>
- 3 回答
- 0 关注
- 586 浏览
添加回答
举报