Looking for the misty rain and the world of mortals, and thinking about poetry and painting in the south of the Yangtze River

WordPress uses Qiniu Cloud or another cloud to use WebP image format

Wandering the Jianghu 2017-02-25 Browse (7228) Comments (5)

WebP format is an image format developed by Google to speed up image loading. Its volume is about 2/3 of that of jpg format. However, in actual use, ordinary people's pictures are not compressed, so the actual volume is only about one-third or less of the original picture. Png images can be compressed into a file size of 50 times without the loss of image quality that can not be distinguished by the naked eye! If an article has more than one picture, the speed will not be improved by a little.

Another cloud WebP image conversion: https://www.upyun.com/webp.html

The problem is that we don't have webp images on hand. Even if there are browsers that don't support webp images, we have to consider it. Fortunately, mainstream image cloud storage provides a choice of input format, and webp is also included in it. As long as you use this type of cloud storage, you can output webp format. What we have to do is to determine when to output webp format. In a simple way, you can judge whether the browser supports the webp format according to whether the accept in the HTTP header contains image/webp.



The following code is directly added to wp-includes/functions. php Middle:

 function fa_converse_webp($matches) {     return $matches[1] .  $matches['2'] .  '!/ format/webp'; //Seven Bulls/ Format/webp is replaced by the following fields     //? imageView2/2/format/webp } function fa_converse_webp_filter($content){     global $post;     $content = preg_replace_callback("/(<img[^>]*src *= *["']?)([^"']*)/i", 'fa_converse_webp' , $content);     return $content; } function fa_is_support_webp(){     return strstr($_SERVER['HTTP_ACCEPT'],'image/webp'); } if ( fa_is_support_webp() ) add_filter('the_content','fa_converse_webp_filter');

The default code supports Youpaiyun. If you use Qiniu, it will

 !/ format/webp

Replace with

 ? imageView2/2/format/webp



(This article is transferred from: To make a big and humble ambition

Title: WordPress uses Qiniu Cloud or another cloud to use WebP image format
Author authorization: Unless otherwise specified, this document is written by Intoxicated with Chinese style Original compilation and authorization Intoxicated with Chinese style blog Publication.
Copyright notice: This article does not use any agreement authorization, and you can freely reprint or use it in any form.
label:
Comment List (5) Comments
 Netizen nickname: Miku_Sama_expo
Miku_Sama_expo tourist 2017-03-13 reply
Qiniuyun WebP image conversion: https://www.upyun.com/webp.html
This should be taken again
 Netizen nickname: parabola
parabola tourist 2017-05-08 reply
How to solve the homepage thumbnail?
 Netizen nickname: Intoxicated with Chinese style
@Intoxicated with Chinese style What homepage thumbnail? Other fixed pictures that do not need to be processed are placed in another space and are not processed
 Netizen nickname: Miku_Sama_expo
Miku_Sama_expo tourist 2017-03-13 reply
Qiniuyun WebP image conversion: https://www.upyun.com/webp.html
This should be taken again
 Netizen nickname: Intoxicated with Chinese style
Intoxicated with Chinese style administrators 2017-03-13 reply
@Intoxicated with Chinese style I have the wrong number

Comment