admin管理员组文章数量:1331659
For a better browser compatibility we often have to maintain multiple format of a media.
For example:
- Image - JPG & WebP
- Image animated - GIF & WebP
- Image transparent - PNG & WebP
- Video - MP4, WebM, OGG
Multiple format file of a same media belongs to a single media attachments logically. Having multiple media attachment for same media file doesn't make sense.
How to handle this situation? How can I have multiple format file for a media attachment?
PS: This is not a question for how to convert files to different format. Assuming we already have converted files or code which converts uploaded files into appropriate formats and saves into filesystem.
Additional Research & Possible Solutions
(I will write a solution after I am satisfied with the research findings and have a solid direction)
Observations
- Currently WP Doesn't supports multiple uploads for a single attachment.
- WordPress attachments is single format.
- Instead of
<img />
a<picture>
tag with appropriate source tag can provide browsers with multiple image formats. A good WP way of multi format image solution could be created if we could modify output ofwp_get_attachment_image()
function but it doesn't have a filter. A trac ticket has been created.
Possible Solution steps
WordPress uses meta field (
_wp_attachment_metadata
) to save file location information. We could save format of each files into a separate metadata and later use WP actions and filters to load it.WordPress has image sizes. File formats have to created for each images sizes.
Video attachments needs multiple formats as well but cover image for video tag is an important component. Extract image from video frame and save into metadata for video attachments. (?)
本文标签:
版权声明:本文标题:uploads - How to host different file formatstypes for a media attachment without creating multiple attachments? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742225255a2436192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论