首页 > 解决方案 > 将 css 样式添加到 og: image

问题描述

是否可以将 CSS 样式添加到您将用于 Facebook 共享的 facebook og:image?我没有使用静态图像,但它们是动态的(php)

所以,这是我当前状态的标签,它只是抓取该特定产品的图像。但是,它只是一个图像。例如,我想使用 CSS 在右上角放置一个彩色块,并在其中放置一些样式文本。

<meta property="og:image" content="<?php echo $data['img_name']; ?>" />

我对 Facebook 分享不是很熟悉,所以不确定这是否可能。

标签: cssfacebook-opengraph

解决方案


不,CSS 是一种样式语言,不会直接应用于图像。调整此元标记时,它不会应用于实际图像。

您可以做的是动态制作不同的图像并在图像顶部添加一个新对象并使用元标记提供此图像。

<?php
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('photo.jpeg');

// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

来源: http: //php.net/manual/en/image.examples-watermark.php


推荐阅读