php微信转发无法显示标题图片,微信分享到朋友圈的链接,内容打开正常,但在微信中分享时封面缩略图图像和...

12

php微信转发无法显示标题图片,微信分享到朋友圈的链接,内容打开正常,但在微信中分享时封面缩略图图像和...

I'd be happy to help you with the issue of not being able to display the title image when sharing a link to WeChat Moments.

Firstly, let's clarify that WeChat has specific requirements for sharing links and images. When sharing a link to WeChat Moments, the platform expects the link to include certain metadata, such as a title, description, and thumbnail image. This metadata is used to generate a preview of the shared content in WeChat.

Now, when you're using PHP to share a link to WeChat Moments, there are a few potential issues that could be causing the title image not to display:

1. Metadata format: WeChat expects the metadata to be in a specific format, which is JSON-encoded. If your PHP code is not generating the metadata in this format, it may not be recognized by WeChat.

2. Thumbnail image size: WeChat requires the thumbnail image to be in a specific size range (typically150x150 pixels). If your thumbnail image is not within this size range, it may not be displayed.

3. Image compression: WeChat also has specific requirements for image compression. If your thumbnail image is not compressed according to these requirements, it may not be displayed.

To resolve the issue, you can try the following:

1. Use a JSON-encoded metadata format: Make sure that your PHP code generates the metadata in a JSON-encoded format. You can use a library like `json_encode()` to achieve this.

2. Resize the thumbnail image: Ensure that your thumbnail image is within the required size range (150x150 pixels). You can use a library like `GD` or `Imagick` to resize the image.

3. Compress the thumbnail image: Compress the thumbnail image according to WeChat's requirements. You can use a library like `GD` or `Imagick` to compress the image.

Here is an example of how you could modify your PHP code to generate the metadata and thumbnail image in the required format:

```php

'title' => 'My Shared Link',

'description' => 'This is a shared link from my website.',

'thumbnail' => ' = json_encode($metadata);

// Resize and compress thumbnail image$image_path = ' = getimagesize($image_path);

if ($image_size[0] >150 || $image_size[1] >150) {

// Resize the image to150x150 pixels $image = imagecreatefromjpeg($image_path);

$new_image = imagecreatetruecolor(150,150);

imagecopyresampled($new_image, $image,0,0,0,0,150,150, $image_size[0], $image_size[1]);

imagejpeg($new_image, 'thumbnail.jpg',80);

// Compress the thumbnail image $compressed_image = imagecreatefromjpeg('thumbnail.jpg');

imagejpeg($compressed_image, 'thumbnail_compressed.jpg',20);

}

// Share the link to WeChat Moments$wx_url = ' = 'My Shared Link';

$wx_description = 'This is a shared link from my website.';

$wx_thumbnail = ' Use SDK to share the linkWXImageObject imgObj = new WXImageObject($wx_thumbnail);

WXMediaMessage msg = new WXMediaMessage();

msg.mediaObject = imgObj;

msg.title = $wx_title;

msg.description = $wx_description;

// Share the link to WeChat Moments$wx_sdk->sendText($wx_url, $msg);

?>

```

In this example, we generate the metadata in a JSON-encoded format and resize/compress the thumbnail image according to WeChat's requirements. We then use the SDK to share the link to WeChat Moments.

I hope this helps! Let me know if you have any further questions or issues.

转发朋友圈php微信转发无法显示标题图片

版权声明:除非特别标注,否则均为网络文章,侵权请联系站长删除。

上一篇 php微信转发无法显示标题图片,解决微信二次分享不显示摘要和图片的问题

下一篇 微信转发朋友圈的php代码,微信开发 分享朋友圈或好友代码