Hexo-Live-Photo User Guide
Hexo-live-photo
A lightweight and user-friendly Hexo plugin for displaying Live Photos (dynamic photos) and similar dynamic images taken by devices like iPhones and Androids in your blog posts.
Origin and Introduction
Modern smartphones (such as iPhone’s Live Photo and similar features on some Android devices) can capture dynamic photos, recording approximately 3 seconds of video and audio before and after the shot. However, when deploying blog posts to static websites, these dynamic photos are often reduced to static JPEG images, losing their vivid essence.
Hexo-live-photo was created to solve this problem. It parses Live Photo resources (a .jpg
image and a .mp4
video) and utilizes HTML5 video playback technology to perfectly restore the dynamic photo playback effect in your Hexo blog without affecting page load performance, making your memories more vivid.
Installation
Run the following command in the root directory of your Hexo blog:
1 | npm install hexo-live-photo --save |
Configuration
Add the following options to the main configuration file _config.yml
of Hexo:
1 | # Live Photo Plugin Configuration |
Usage Guide
Preparing Resource Files
Ensure you have the two core files for the dynamic photo:
- Video File (
.mp4
): The video part of the dynamic photo - Cover Image File (
.jpg
): The static cover part of the dynamic photo
Place these two files in your Hexo blog source directory, for example, source/images/posts/
.
Example File Structure:
1 | source/images/posts/my-vacation.jpg |
It is recommended to use object storage or a CDN to host these resources to improve loading speed and user experience.
Example URL Structure:
1 | https://your-cdn.com/images/posts/my-vacation.jpg |
Using in Articles
Use the {% live_photo %}
tag anywhere in your Markdown articles (.md
files) where you need to insert a dynamic photo.
Basic Syntax:
1 | {% livephoto image_path video_path %} |
Displaying Two Dynamic Photos in a Row:
The plugin includes built-in CSS code that uses Flexbox layout, allowing you to achieve this with HTML code.
1 | <div class="image-grid"> |
Advanced Usage
You can add additional parameters within the tag, such as custom titles, and set width and height.
Extended Syntax:
1 | {% livephoto image_path video_path "Image Description" "Optional Title" "Optional Width" "Optional Height" %} |
Example:
1 | {% livephoto /images/sunset.jpg /videos/sunset.mp4 "Beach Sunset" "Maldives Sunset Beauty" "600px" %} |
Implementation Principle
The plugin generates the following HTML structure:
1 | <div class="live-photo-container" id="livePhoto"> |
- Interaction: When you scroll down the page and the image fully enters the viewport, the Live Photo will auto-play once. The video will play again when the mouse hovers or when it is touched.
- Appearance: The “Live” badge can be displayed in one of the four corners of the image to enhance the recognition of dynamic photos.
Notes
- Video Format: It is recommended to use MP4 format encoded with H.264 to ensure compatibility with most browsers.
- Performance: Although the plugin is optimized, please ensure the video files are not too large and consider using a fast CDN to host video resources.
- Browser Support: Ensure your browser supports HTML5 video playback. After testing, the Xiaomi browser will convert the video to a video player, although this does not affect viewing, you will lose the opportunity to download the static image and the dynamic playback experience.
- WeChat Browser: Since the WeChat built-in browser has strict restrictions on auto-play, it is recommended to enable the
weixin_disable_autoplay
option to avoid white screen issues caused by auto-play.
Change Log
- V1.1.2: Fixed the display issue of the loading indicator, added CSS styles for displaying two images in a row on mobile devices.
- V1.1.1: Added compatibility support for WeChat, fixed auto-play issues in some browsers.
Contribution
Welcome to submit Issues and Pull Requests!
License
MIT
Support
If this plugin has helped you, please give a star ⭐. If you encounter any issues while using it, please submit an Issue.