gpt4 book ai didi

javascript - 动态 og :image with Variables from original page

转载 作者:行者123 更新时间:2023-11-30 19:56:26 26 4
gpt4 key购买 nike

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

最佳答案

他们可能在他们的服务器上运行了一些代码来查看查询参数并生成图像。这就是您在 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

关于javascript - 动态 og :image with Variables from original page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53937709/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com