Linux 软件免费装
Banner图

Images to WebP

开发者 kubiq
更新时间 2025年12月2日 06:57
捐献地址: 去捐款
PHP版本: 5.6 及以上
WordPress版本: 6.9
版权: GPLv2 or later
版权网址: 版权信息

标签

media pictures optimize convert

下载

1.4 1.5 1.6 1.8 1.9 1.7 4.4 4.8 4.7 1.2 1.0 1.9.1 1.3 2.0 4.1 1.1 3.0 4.0 4.2 4.3 4.5 4.6

详情介绍:

Statistics say that WebP format can save over a half of the page weight without losing images quality. Convert PNG, JPG and GIF images to WebP and speed up your web, save visitors download data, make your Google ranking better. Hooks for developers itw_extensions Maybe you want to support also less famous JPEG extension like jpe, jfif or jif add_filter( 'itw_extensions', 'extra_itw_extensions', 10, 1 ); function extra_itw_extensions( $extensions ){ $extensions[] = 'jpe'; $extensions[] = 'jfif'; $extensions[] = 'jif'; return $extensions; } itw_sizes Maybe you want to disable WebP for thumbnails add_filter( 'itw_sizes', 'disable_itw_sizes', 10, 2 ); function disable_itw_sizes( $sizes, $attachmentId ){ unset( $sizes['thumbnail'] ); return $sizes; } itw_htaccess Maybe you want to modify htaccess rules somehow add_filter( 'itw_htaccess', 'modify_itw_htaccess', 10, 2 ); function modify_itw_htaccess( $rewrite_rules ){ // do some magic here return $rewrite_rules; } itw_abspath Maybe you use roots.io/bedrock or other custom folder structure add_filter( 'itw_abspath', 'modify_itw_abspath', 10, 2 ); function modify_itw_abspath( $abspath ){ return trailingslashit( WP_CONTENT_DIR ); } $images_to_webp->convert_image() 或许你想使用其他插件自动生成 WebP add_action( 'XXPLUGIN_image_created', 'XX_images_to_webp', 10, 2 ); function XX_images_to_webp( $image_path ){ global $images_to_webp; $images_to_webp->convert_image( $image_path ); }

安装:

  1. Upload images-to-webp directory to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress

常见问题:

Plugin requirements

It should work almost everywhere ;) PHP 5.6 or higher GD or Imagick extension with WebP support Enabled server modules: mod_mime, mod_rewrite

WebP images stored location

WebP images are generated in same directory as original image. Example: original img: /wp-content/uploads/2019/11/car.png webp version: /wp-content/uploads/2019/11/car.png.webp

How to get original image from the browser?

Just add ?no_webp=1 to the URL and original JPG/PNG will be loaded

How to check if plugin works?

When you have installed plugin and converted all images, follow these steps:

  1. Run Google Chrome and enable Dev Tools (F12).
  2. Go to the Network tab click on Disable cache and select filtering for Img (Images).
  3. Refresh your website page.
  4. Check list of loaded images. Note Type column.
  5. If value of webp is there, then everything works fine.

NGiNX and Apache together

If you have some proxy setup or some other combination of NGiNX and Apache on your server, then probably .htaccess changes won't work and you will need to ask your hosting provider to disable NGiNX direct processing of image static files.

Apache .htaccess

Plugin should automatically update your .htaccess with needed rules. In case it's not possible to write them automatically, screen with instructions will appear. Anyway, here is how it should look like: ` AddType image/webp .webp RewriteEngine On RewriteCond %{HTTP_ACCEPT} image/webp RewriteCond %{REQUEST_FILENAME} "/" RewriteCond %{REQUEST_FILENAME} ".(jpg|jpeg|png|gif)$" RewriteCond %{REQUEST_FILENAME}.webp -f RewriteCond %{QUERY_STRING} !no_webp RewriteRule ^(.+)$ $1.webp [NC,T=image/webp,E=webp,L] `

NGiNX 配置

After you activate plugin, screen with instructions will appear. Anyway, here is how it should look like: You need to add this map directive to your http config, usually nginx.conf ( inside of the http{} section ): `map $arg_no_webp $no_webp{ default ""; "1" "no_webp"; } map $http_accept $webp_suffix{ default ""; "~*webp" ".webp"; }` or without map directive: `if ( $http_accept ~ "image/webp" ) { set $webp .webp ; } location ~ (.).(?:png|jpe?g|gif)$ { if ( -f $document_root$1.webp ) { set $webp serve$webp ; } if ( $webp = "serve.webp" ) { return 301 '$1.webp'; } }` then you need to add this to your server block, usually site.conf or /nginx/sites-enabled/default ( inside of the server{} section ): location ~* ^/.+\.(png|gif|jpe?g)$ { add_header Vary Accept; try_files $uri$webp_suffix$no_webp $uri =404; }

ISP Manager

Are you using ISP Manager? Then it's probably not working for you, but no worries, you just need to go to WWW domains and delete jpg|jpeg|png from the Static content extensions field.

Delete all generated WebP images

There is no button to do that and it will also not delete generated WebPs automatically when you deactivate the plugin, but if you really need this, you can run some shell command to achieve this: find . -type f -name "*.webp" -exec bash -c 'if [ -f "${1%.webp}" ]; then echo "Deleting $1"; rm "$1"; fi' _ {} \; This will find all the files with a .webp extension and if there is similar file with the exact filename, but without the .webp extension, then it will delete it.

更新日志:

4.8 4.7 4.6 4.5 4.4 4.3 4.2 4.1 4.0 3.1 3.0 2.0 1.9.1 1.9 1.8 1.7 1.6 1.5 1.4 1.3 1.2 1.1 1.0