php - 如何将 Open Graph 图像设置为 PHP 生成的图像?
问题描述
我有一个 PHP 页面,它打开一个目录,选择一个随机图像,并将页面设置为仅该图像。
<?php
$imageDir = 'random_images_dir/';
$images = glob($imageDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)];
$file_out = $randomImage;
if (file_exists($file_out)) {
$image_info = getimagesize($file_out);
header('Content-Type: ' . $image_info['mime']);
header('Content-Length: ' . filesize($file_out));
readfile($file_out);
}
else {
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
}
?>
是否可以将链接发送为https://example.com/random_image.php
(例如在 Discord 中)并将生成的图像嵌入 Open Graph 中?通常在发送链接时,它会选择一张图片,然后只发送该图片。
解决方案
推荐阅读
- javascript - Is it possible to know the 'this' object before calling the constructor?
- android - 有没有调整位图图像大小的方法?
- jpa - 使用 jpa 编辑实体
- angular - 从响应中的 URL 下载图像
- hyperledger-fabric - Hyperledger Composer 通道概念
- google-maps - 传单如何将 L.CRS.SIMPLE 坐标转换为普通 L.CRS.Earth 坐标
- css - 两列结帐 Woocommerce
- c# - C# + SQL + Xamarin Android:
- php - PhpStorm 重新格式化不同于 phpcs (Zend CodeStyle)
- mysql - 在第二个用户登录后,第一个用户数据在主页中与第二个用户更新