带有原始页面变量的动态 og:image

Dynamic og:image with Variables from original page

我很难在网上找到关于这个主题的任何资源,所以我想我会开始讨论。我很好奇如何根据原始 URL 中的数据使 og:image 动态化。例如,trustpilot.com 为每个显示网站名称和评级的站点提供动态 og:image。我自己尝试了一个获取请求,其中包含图像的必要信息,然后被重定向到另一个将生成图像的 URL,然后最终将您重定向到新创建的图像,但它没有真的没有像我预期的那样工作......提前致谢

他们的服务器上可能有一些代码 运行 可以查看查询参数并生成图像。这就是您在 PHP:

中执行此操作的方式
<?php

header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreate(400, 30);
$textcolor = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 0, 0, $text, $textcolor);
imagepng($im);
imagedestroy($im);

?>

然后将您的 og:image 设置为 yourwebsite.com/generateImage.php?text=Example%20text