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

推荐订阅源

T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cisco Blogs
AWS News Blog
AWS News Blog
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
美团技术团队
T
Threatpost
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cyber Attacks, Cyber Crime and Cyber Security
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
C
Cybersecurity and Infrastructure Security Agency CISA
F
Full Disclosure
博客园_首页
N
Netflix TechBlog - Medium
Security Latest
Security Latest
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recent Announcements
Recent Announcements
博客园 - Franky
P
Palo Alto Networks Blog
Project Zero
Project Zero
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Cisco Talos Blog
Cisco Talos Blog
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 【当耐特】
GbyAI
GbyAI

大于二三

再次来到汕头和汕尾 | 大于二三 把网站删除 | 大于二三 我的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;
}