惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

大于二三

再次来到汕头和汕尾 | 大于二三 把网站删除 | 大于二三 我的2024 | 大于二三 写给那位自由的人 | 大于二三 2025 | 大于二三 成长到25岁的感慨 | 大于二三 汕尾 | 大于二三 这一年的故事很简单 | 大于二三 去追追不到的太阳 | 大于二三
让你的WordPress支持实况图 | 大于二三
虾虾剥虾壳 · 2025-02-18 · via 大于二三

文章参考于iami233的 Hexo 中实现 Live Photos 支持

什么是Live Photo?
它可以在你按下快门前后记录大约1.5秒的视频和音频,从而让照片“活”起来。
本质上是由张 JPG 图片以及一个MOV 视频文件所组成

原来一直就想给自己的博客做一个实况图的,之前也有过询问GPT4.0,但是给出的答案还是无法让wordpress支持实况图,直到前几天兔子(HELLO)给我发了这篇文章“ Hexo 中实现 Live Photos 支持”后,引用了这位大佬的代码,让Chatgpt写出了让WordPress支持Live photo的方法

在你的 functions.php 文件里添加以下代码

/** LivePhotosKit JS **/
function enqueue_livephotoskit() {
    ?>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const livePhotoElements = document.querySelectorAll('[data-live-photo]');
            if (livePhotoElements.length > 0) {
                const script = document.createElement('script');
                script.src = 'https://cdn.apple-livephotoskit.com/lpk/1/livephotoskit.js';
                document.head.appendChild(script);
            }
        });
    </script>
    <?php
}
add_action('wp_footer', 'enqueue_livephotoskit');

/** 插入文章的短代码 **/
function live_photo_shortcode($atts) {
    $atts = shortcode_atts(array(
        'image' => '',
        'video' => '',
        'caption' => '',
        'width' => '320px',
        'height' => '320px'
    ), $atts, 'livephoto');

    if (empty($atts['image']) || empty($atts['video'])) {
        return '<p>错误:必须提供图片和视频链接。</p>';
    }

    ob_start(); ?>
    <figure style="text-align: center; color: #000;">
        <div 
            data-live-photo 
            data-photo-src="<?php echo esc_url($atts['image']); ?>" 
            data-video-src="<?php echo esc_url($atts['video']); ?>" 
            style="width: <?php echo esc_attr($atts['width']); ?>; 
                   height: <?php echo esc_attr($atts['height']); ?>; 
                   margin: 0 auto; overflow: hidden;">
        </div>
        <?php if (!empty($atts['caption'])) : ?>
            <figcaption style="margin-top: 4px;"><?php echo esc_html($atts['caption']); ?></figcaption>
        <?php endif; ?>
    </figure>
    <?php
    return ob_get_clean();
}
add_shortcode('livephoto', 'live_photo_shortcode');
?>

当你在 WordPress 文章中添加 Live Photo,可以使用以下代码:

[livephoto image="你的jpg图片" video="你的mov视频" caption="图片文案"]

然后它会被解析为:

<figure style="text-align: center; color: #000;">
    <div 
        data-live-photo 
        data-photo-src="你的jpg图片" 
        data-video-src="你的mov视频" 
        style="width: 320px; height: 320px; margin: 0 auto; overflow: hidden;">
    </div>
    <figcaption style="margin-top: 4px;">图片文案</figcaption>
</figure>

图片演示:

图片演示

当苹果的Live Photo图被拆解的时候,会有一个Heic图片和一个Mov视频。
注意!Heic图片需要转为Jpg后才可以正常使用


如果你想用CSS改变实况图的的样式的时候,可以用以下代码自行修改(这里只加了圆角效果)

[data-live-photo] canvas, 
[data-live-photo] video, 
[data-live-photo] div {
    border-radius: 10px !important;
    overflow: hidden;
}