Tyepcho 博客添加 Open Graph 图片

在 Typecho 中使用:

<meta property="og:image" content="//example.org/og/?title=<?php $this->title(); ?>&des=<?php $this->description(); ?>"/>
<?php

function og($title, $des) {
    $img = imagecreatefrompng('./bg.png');
    $black = imagecolorallocate($img, 0, 0, 0);
    $title_font = './ZhanKuKuaiLeTi2016XiuDingBan-1.ttf';
    $desc_font = './ZhanKuKuaiLeTi2016XiuDingBan-1.ttf';
    $title_lines = explode("\n", wordwrap($title, 30, "\n", true));
    $desc_lines = explode("\n", wordwrap($des, 60, "\n", true));
    $title_y = 60;
    $desc_y = 200;

    foreach ($title_lines as $line) {
        imagettftext($img, 55, 0, 10, $title_y, $black, $title_font, $line);
        $title_y += 65;
    }

    foreach ($desc_lines as $line) {
        imagettftext($img, 25, 0, 10, $desc_y, $black, $desc_font, $line);
        $desc_y += 30;
    }

    header('Content-Type: image/png');
    imagepng($img);
    imagedestroy($img);
}

// Retrieve title and description from URL parameters
$title = isset($_GET['title']) ? $_GET['title'] : 'Default Title';
$des = isset($_GET['des']) ? $_GET['des'] : 'Default Description';

// Example usage:
og($title, $des);
?>

推荐:ColoCrossing 美国 VPS 1C1G 年付$10.99 USD 支持支付宝/PayPal 常规 VPS 套餐使用优惠码 CNY5824 循环 58%折扣 1C1G 折后月付$1.66 USD

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理