webp是Google出的一种图片格式,是一种同时提供了有损压缩与无损压缩(可逆压缩)的图片文件格式,派生自影像编码格式VP8,被认为是WebM多媒体格式的姊妹项目,是由Google在购买On2 Technologies后发展出来,以BSD授权条款发布。
让WordPress支持webp,能对文件体积大幅度减小。
在主题或者插件添加如下代码来支持webp
添加到主题functions.php里
function webp_filter_mime_types($array) { $array['webp'] = 'image/webp'; return $array; } add_filter('mime_types', 'webp_filter_mime_types');
支持上传了,但是不支持预览,需要手动处理,处理后能在媒体中心直接预览
function webp_file_display($result, $path) { $info = @getimagesize( $path ); if($info['mime'] == 'image/webp') { $result = true; } return $result; } add_filter( 'file_is_displayable_image', 'webp_file_display');
支持SVG
SVG是一种图像文件格式,它的英文全称为Scalable Vector Graphics,意思为可缩放的矢量图形。可以无限制放大图片大小不失真。
在主题或者插件添加如下代码来支持svg
下面的函数是让WordPress支持上传svg文件,同时,这个函数修改修改还能支持上传其他的文件,只需要添加到数组即可
function upload_support($mimes = array()) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'upload_support');
发表评论