抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

效果图

657d53c6411eb.png

代码

在Typecho中使用:

1
<meta property="og:image" content="//example.org/og/?title=<?php $this->title(); ?>&des=<?php $this->description(); ?>"/>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?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);
?>


本站使用 Volantis 作为主题,您可以在 GitHub 找到本站源码

本站总访问量为 访客数为

萌ICP备20235354号

Feed(Atom)