Php 如何从给定链接获取图像缩略图?
在Facebook上共享链接时,Facebook会从给定链接中获取标题、元描述和图像 我不知道他们是怎么得到这个图像的。我也在网上搜索,但找不到办法Php 如何从给定链接获取图像缩略图?,php,Php,在Facebook上共享链接时,Facebook会从给定链接中获取标题、元描述和图像 我不知道他们是怎么得到这个图像的。我也在网上搜索,但找不到办法 如何从给定URL获取图像缩略图?好的,使用file\u put\u contents()将文件保存到服务器,然后您可以创建缩略图。您无法直接从url获取缩略图 按如下方式保存文件: $url = 'http://example.com/image.ext'; $img = 'yourImgNameOrWithPath.ext'; file_put_
如何从给定URL获取图像缩略图?好的,使用file\u put\u contents()将文件保存到服务器,然后您可以创建缩略图。您无法直接从url获取缩略图 按如下方式保存文件:
$url = 'http://example.com/image.ext';
$img = 'yourImgNameOrWithPath.ext';
file_put_contents($img, file_get_contents($url));
使用以下代码创建缩略图:
function createThum($filename,$thumb_width,$thumb_height,$destination)
{
$my_input_file = $filename;
$my_output_file = $destination;
$jpeg_quality = 100;
$size = getimagesize($my_input_file);
//$thumb_width = ($size[0] / $size[1]) * $thumb_height;
$src_img = imagecreatefromjpeg($my_input_file);
$dst_img = imagecreatetruecolor($thumb_width,$thumb_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1]);
imagejpeg($dst_img, $my_output_file, $jpeg_quality);
imagedestroy($src_img);
imagedestroy($dst_img);
return true;
}
正如我所知,他们在页面上得到第一个大的(防止图标解析)图像。