Once everything is working fine, I recommend cleaning the database of any trace of jpg, it helped me to remove a lot of jpg garbage.
]]>Hi there @katsushi-kawamori, hope you’re doing well. We’ve been installing your plugin on more of our sites and it’s been a great experience overall.
We did end up finding one bug on one of our WooCommerce sites in which the image thumbnails were appearing broken in the Media Library due to it trying to load them as image-100×100.png rather than image-100×100.webp.
Strangely, the bug was only happening on one of our WooCommerce sites but not the others. After some initial debugging, we first thought that it was due to a three-way plugin conflict with WooCommerce, your plugin, and a WooCommerce extension, but after digging deep into the issue, we found that it wasn’t directly related to WooCommerce or the other plugin but rather due to any two plugins defining the same image size.
Here’s an example of a snippet that will break the thumbnails when your plugin’s “Replace” setting is enabled:
add_action( 'init', 'webpdebug_add_image_sizes');
function webpdebug_add_image_sizes()
{
add_image_size( 'webpdebug_bugtest_size', 100, 100, 1 );
add_image_size( 'woocommerce_gallery_thumbnail', 100, 100, 1 );
}
After doing a deep dive into your plugin’s code, we found that this code in /lib/class-pluswebp.php was the source of the issue:
foreach ( (array) $metadata['sizes'] as $key => $value )
{
$file_thumb = $value['file'];
$file_thumb_webp = $this->change_ext( $file_thumb, $ext, $pluswebp_settings['addext'] );
$ret = $this->create_webp( $path . $file_thumb, $mime_type, $path . $file_thumb_webp, $pluswebp_settings['quality'], $pluswebp_settings['output_mime'] );
if ( $ret || file_exists($path . $file_thumb_webp) )
{
$metadata_webp['sizes'][ $key ]['file'] = $file_thumb_webp;
$metadata_webp['sizes'][ $key ]['mime-type'] = $pluswebp_settings['output_mime'];
$webp_size = filesize( $path . wp_basename( $file_thumb_webp ) );
$metadata_webp['sizes'][ $key ]['filesize'] = $webp_size;
if ( $pluswebp_settings['replace'] )
{
wp_delete_file( $path . $file_thumb );
$this->change_db( $url . $file_thumb, $url . $file_thumb_webp );
}
}
}
The code above has a bug where, if the WebP or AVIF image already exists, it won’t update the database value due to the create_webp call returning false.
We experimented with several different fixes and found that the most straightforward fix is just a simple fallback condition that checks to see if the image already exists:
if ( $ret || file_exists($path . $file_thumb_webp) )
Technically there are other possible ways to fix it like performing the file_exists check in the create_webp function and returning true instead of false, but either way should be fine.
]]>Hi there, we tried permanently converting all of our media library images to WebP with this plugin. It worked well for most images, but some of our PNG images had their transparent background converted to black pixels, so we had to do a rollback.
Here’s an example of one of the affected images: https://sitebolts.com/temp/icon3.png
And what it looks like after conversion: https://sitebolts.com/temp/icon3.webp
Other than that, the plugin worked great; most of our image sizes were reduced by half or more. Would it be possible to fix the transparency issue?
]]>Hello.
Looks like it doesn`t support your Image to text plugin.
]]>Hi Boss.. I have a solution for support Woo and some othet meta.. The problem lies in the imperfection of the function, which does not take into account some aspects DB replaceing..
This is happening because you are not updating additional meta fields and options. For example:
Code DB – Key meta_value
meta_value = "a:6:{s:5:"width";i:1000;s:6:"height";i:1000;s:4:"file";s:32:"2018/04/Miroos-cro-s.webp";s:5:"sizes";a:7:{s:12:"medium_large";a:5:{s:4:"file";s:32:"Miroos-cro-s-768x768.webp";s:5:"width";i:768;s:6:"height";i:768;s:9:"mime-type";s:10:"image/webp";s:8:"filesize";i:91668;}s:21:"woocommerce_thumbnail";a:6:{s:4:"file";s:32:"Miroos-cro-s-300x300.webp";s:5:"width";i:300;s:6:"height";i:300;s:9:"mime-type";s:10:"image/webp";s:9:"uncropped";b:1;s:8:"filesize";i:21814;}s:18:"woocommerce_single";a:5:{s:4:"file";s:32:"Miroos-cro-s-600x600.webp";s:5:"width";i:600;s:6:"height";i:600;s:9:"mime-type";s:10:"image/webp";s:8:"filesize";i:66512;}s:29:"woocommerce_gallery_thumbnail";a:5:{s:4:"file";s:32:"Miroos-cro-s-100x100.webp";s:5:"width";i:100;s:6:"height";i:100;s:9:"mime-type";s:10:"image/webp";s:8:"filesize";i:4306;}s:12:"shop_catalog";a:5:{s:4:"file";s:31:"Miroos-cro-s-300x300.jpg";s:5:"width";i:300;s:6:"height";i:300;s:9:"mime-type";s:10:"image/jpeg";s:9:"uncropped";b:1;}s:11:"shop_single";a:4:{s:4:"file";s:31:"Miroos-cro-s-600x600.jpg";s:5:"width";i:600;s:6:"height";i:600;s:9:"mime-type";s:10:"image/jpeg";}s:14:"shop_thumbnail";a:4:{s:4:"file";s:31:"Miroos-cro-s-100x100.jpg";s:5:"width";i:100;s:6:"height";i:100;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}s:8:"filesize";i:149044;}"
ARRAY ()
meta_value = array(
'width' => 1000,
'height' => 1000,
'file' => '2018/04/Miroos-cro-s.webp',
'sizes' => array(
'medium_large' => array(
'file' => 'Miroos-cro-s-768x768.webp',
'width' => 768,
'height' => 768,
'mime-type' => 'image/webp',
'filesize' => 91668,
),
'woocommerce_thumbnail' => array(
'file' => 'Miroos-cro-s-300x300.webp',
'width' => 300,
'height' => 300,
'mime-type' => 'image/webp',
'uncropped' => true,
'filesize' => 21814,
),
'woocommerce_single' => array(
'file' => 'Miroos-cro-s-600x600.webp',
'width' => 600,
'height' => 600,
'mime-type' => 'image/webp',
'filesize' => 66512,
),
'woocommerce_gallery_thumbnail' => array(
'file' => 'Miroos-cro-s-100x100.webp',
'width' => 100,
'height' => 100,
'mime-type' => 'image/webp',
'filesize' => 4306,
),
'shop_catalog' => array(
'file' => 'Miroos-cro-s-300x300.jpg',
'width' => 300,
'height' => 300,
'mime-type' => 'image/jpeg',
'uncropped' => true,
),
'shop_single' => array(
'file' => 'Miroos-cro-s-600x600.jpg',
'width' => 600,
'height' => 600,
'mime-type' => 'image/jpeg',
),
'shop_thumbnail' => array(
'file' => 'Miroos-cro-s-100x100.jpg',
'width' => 100,
'height' => 100,
'mime-type' => 'image/jpeg',
),
),
'image_meta' => array(
'aperture' => '0',
'credit' => '',
'camera' => '',
'caption' => '',
'created_timestamp' => '0',
'copyright' => '',
'focal_length' => '0',
'iso' => '0',
'shutter_speed' => '0',
'title' => '',
'orientation' => '0',
'keywords' => array(),
),
'filesize' => 149044,
);
As you can see, it is an array. Without my correction, it shows that your code is too simple and does not take into account WooCommerce meta support. Therefore, I advise you to listen to me rather than criticize my coding style. I’ve been coding since I was 15, and now I am 45. I’ve been working at Microsoft up to today, so I am trying to help you become even better.
Report on the Modification of the change_db
Function Purpose of the Changes
The primary goal of the changes was to correctly update all necessary entries in the WordPress database after converting images to the WebP format. This includes replacing old image URLs with new ones, especially for WooCommerce products. Issues with the Original Code
wp_posts
table, resulting in some image URLs remaining unchanged, particularly for WooCommerce products.wp_postmeta
and wp_options
Tables: The code did not account for updating image URLs in the wp_postmeta
and wp_options
tables, where image references are also stored.Changes Made
wp_postmeta
and wp_options
Tables: Updates were added for the wp_postmeta
and wp_options
tables to ensure correct image URL references across the database.change_db
Function: The function was improved to perform URL replacements in three tables (wp_posts
, wp_postmeta
, wp_options
), ensuring a more comprehensive and correct database update.Original Code
private function change_db($before_url, $after_url) {
global $wpdb;
/* Replace */
$wpdb->query(
$wpdb->prepare(
"
UPDATE {$wpdb->prefix}posts
SET post_content = replace(post_content, %s, %s)
",
$before_url,
$after_url
)
);
}
Updated Code
private function change_db(string $before_url, string $after_url): void {
global $wpdb;
try {
// Ensure URLs are valid strings
if (empty($before_url) || empty($after_url)) {
throw new Exception('URLs must not be empty.');
}
// Update wp_posts table
$posts_query = $wpdb->prepare(
"UPDATE {$wpdb->prefix}posts SET post_content = REPLACE(post_content, %s, %s)",
$before_url,
$after_url
);
$posts_result = $wpdb->query($posts_query);
if ($posts_result === false) {
throw new Exception('Failed to update wp_posts table.');
}
// Update wp_postmeta table
$postmeta_query = $wpdb->prepare(
"UPDATE {$wpdb->prefix}postmeta SET meta_value = REPLACE(meta_value, %s, %s)",
$before_url,
$after_url
);
$postmeta_result = $wpdb->query($postmeta_query);
if ($postmeta_result === false) {
throw new Exception('Failed to update wp_postmeta table.');
}
// Update wp_options table
// Use a safe method to update options that may contain serialized data
$options = $wpdb->get_col("SELECT option_name FROM {$wpdb->prefix}options WHERE option_value LIKE '%{$before_url}%'");
foreach ($options as $option_name) {
$option_value = get_option($option_name);
if (is_array($option_value)) {
foreach ($option_value as $key => $value) {
if (is_string($value) && strpos($value, $before_url) !== false) {
$option_value[$key] = str_replace($before_url, $after_url, $value);
}
}
update_option($option_name, $option_value);
} elseif (is_string($option_value) && strpos($option_value, $before_url) !== false) {
$updated_value = str_replace($before_url, $after_url, $option_value);
update_option($option_name, $updated_value);
}
}
// Log success message
error_log("Successfully replaced URLs in wp_posts, wp_postmeta, and wp_options tables: $before_url to $after_url");
} catch (Exception $e) {
// Log the error message
error_log('Error changing database content: ' . $e->getMessage());
}
}
Using the Updated Function
The change_db
function should be called after converting an image to the WebP format and saving it on the server. The function takes two parameters: the URL of the image before and after the format change. This will ensure that all database records referencing this image are correctly updated.
// Example of calling the change_db function
/* Replace */
$this->change_db( $this->upload_url . '/' . $metadata['file'], $this->upload_url . '/' . $file_webp );
This update ensures the correct replacement of all image URLs in the WordPress database, maintaining the stability and accuracy of your site’s functionality.
]]>Unable to convert webp when connecting to third-party image repositories (such as Cloudflare R2 and Amazon S3)
]]>Hello,
try convert: jpg, png only
I attempted to convert all the images in my blog and shop, which is about 500 images. I started the process, and it stopped at 20% without any error. When I tried to run it again, I received the following error: PHP Fatal error: Palette image not supported by webp in X:\xampp\htdocs\wp-includes\class-wp-image-editor.php on line 592. I attempted to fix it myself by adding the following rules to handle the imagecreatetruecolor
function in public function get_allimages()
and enhancing the create_webp
function:
private function create_webp( $filename, $mime_type, $filename_webp ) {
if ( ! file_exists( $filename ) ) {
return false;
}
if ( file_exists( $filename_webp ) ) {
return false;
}
$pluswebp_settings = get_option( 'pluswebp' );
@set_time_limit( 60 );
wp_raise_memory_limit( 'pluswebp' );
$ret = false;
switch ( $mime_type ) {
case 'image/jpeg':
$src = imagecreatefromjpeg( $filename );
$img = imagecreatetruecolor( imagesx( $src ), imagesy( $src ) );
imagealphablending( $img, true );
break;
case 'image/png':
$src = imagecreatefrompng( $filename );
$img = imagecreatetruecolor( imagesx( $src ), imagesy( $src ) );
imagealphablending( $img, false );
imagesavealpha( $img, true );
break;
case 'image/gif':
// Check if GIF has a palette
$image_data = getimagesize( $filename );
if ( isset( $image_data['channels'] ) && $image_data['channels'] > 3 ) {
// Log the file that couldn't be converted due to palette
$this->log_unsupported_webp_file( $filename );
return false;
}
$src = imagecreatefromgif( $filename );
$img = imagecreatetruecolor( imagesx( $src ), imagesy( $src ) );
imagealphablending( $img, true );
break;
default:
// Log unsupported mime types
$this->log_unsupported_webp_file( $filename );
return false;
}
imagecopy( $img, $src, 0, 0, 0, 0, imagesx( $src ), imagesy( $src ) );
imagedestroy( $src );
$ret = imagewebp( $img, $filename_webp, $pluswebp_settings['quality'] );
imagedestroy( $img );
return $ret;
}
// Function to log unsupported WebP files using WooCommerce Logger
private function log_unsupported_webp_file( $filename ) {
if ( class_exists( 'WC_Logger' ) ) {
WC_Logger::instance()->debug( 'Unsupported WebP file: ' . $filename );
}
}
Additionally, I added various logs to understand the root cause of the conversion issue. The “Palette” error has disappeared, but the process reaches 100% and reports as completed. However, after refreshing the page, it shows “Found 284 media that can be generated.” This might be caused by various reasons. It also seems that the library does not delete the original files, although I have enabled the option.
Could you provide some advice? Perhaps you have a debug version to determine why it stops converting images even though it reports 100% progress. I’ve tried making various adjustments to find the root cause of the issue, but since I’m not the developer, it’s difficult for me to figure out how it works.
Thank you.
]]>插件很简洁很棒,能否增加一个限制原图大小的功能啊,我不想再去装一个插件去缩放原图大小,而且似乎也没有这样纯粹的插件存在
比如我上传一个1920*1080的图片,转为webp后,uploads文件夹内会生成四张图片:分别为原图、大尺寸、中尺寸、小尺寸,如果插件可以直接缩放原图为中尺寸分辨率的话,uploads文件夹只会生成两张:原图、小尺寸,这样又极大减少了占用空间
]]>Hi, since version 4.07 the plugin offers the possibility to use wp-cli.
Are there any parameters for this?
For example, I would like to create a cronjob and only have a certain number of images processed per run.
Does wp-cli also replace the original images?
Regards
Olaf
Hello my friend!
I don’t care about browsers that don’t support WEBP, so I just wanted to replace it and not interfere with any cache delivery.
I just need to convert and replace PNG and JPG with WEBP ensuring smooth compatibility with CloudFlare and the edge cache.
Is there such a possibility?
]]>When auto-transforme to Webp is On, images of Product Gallery are broken in admin-panel. (in front-end it’s ok).
]]>If I no select any media type, search 35 media for generate, i like know what media type are ? No jpeg, png, bmp, gif…
Why search if I no select any media? Why no show the files for check what files are?
If I select all the types media, don’t detect my files jpg, so have one error in detect the files
Maybe the plugin search for jpeg instead of jpg??
]]>When clicking on Regenerate Thumbnails I see that somehow the size “2048×2048: 2048×2048 pixels (proportionally resized to fit inside dimensions)” is failing. Is there a size limit? I set my memory to memory_limit = 1024M
in the hopes it would help. I am using PHP Version 8.2.9 and Imagick is not installed.
First delete the plugin
Close the Tab
Install the plugin again and activate
Press check
Set the quality and type of media, deletion, etc
Press generate
No close the tab, no loose the focus of the tab
If yo have luck like me will work to 100%
I set the quality 97% because the jpg are in 85%
]]>Hello,
Since the last update, the extension’s settings menu is with the Medias menu but when I click on Medias, I no longer have access to the medias library, it’s the plugin that keeps coming back.
The link to the Medias menu: /wp-admin/admin.php?page=plus-webp
The web-plus menu link below: /wp-admin/upload.php?page=plus-webp
Am I the only one?
]]>It worked well, it helped me with 2000 images, but then it stopped progressing.
I stopped it and tried to continue with the conversions, but it doesn’t work.
What could have happened?
A function you can add is to delete the images later.
Or an extra button so that after generating the webp files, you can replace them.
Thank you for the plugin, I hope can find one fix for run again
]]>I have all the images generated in webp with this plugin.
When you enter the cart summary page, the image you are trying to view has the same original .jpg extension and that is why it cannot be viewed
The extension on this page should be replaced with .webp
I have already contacted the developer of the theme but he tells me that it is not a problem with the theme.
Please could you check if it is a plugin bug.
Thank you so much
]]>Hi,
After activating I get this error message:
3-Dec-2023 10:26:45 UTC] PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/demo/public_html/wp-includes/functions.wp-styles.php on line 90
[1
What goes wrong? I am using the latest WordPress.
]]>Hi, I have the latest version of the plugin and when I select “Generate” it does not progress.
How can I fix this problem?
]]>I’m stuck almost on the first picture of the 14k transformations. Where is logging the plugin? I need to check what picture is causing the problem to try to fix it.
]]>Hi,
After installation I tried to use this plugin, however, I always get following error message:
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 12288 bytes) in /var/www/url/public_html/wp-includes/class-wpdb.php on line 2425
In wp-config.php file:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors', 0 );
@ini_set('error_reporting', E_ALL );
define ( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_AUTO_UPDATE_CORE', true );
In php.ini file:
memory_limit = 512M
]]>
Hi there.
Thank for such a great plugin.
I found a little error, whem I uploaed the same filename the plugin will not generate webp version.
In this case I use (TEST.jpg).
The 1st uploaded it will convert to (TEST.webp).
The 2nd uploaded it will NOT convert to webp just the same file same/extension (TEST.jpg).
The 3rd uploaded, plugin will convert to WebP with new name (TEST-1.jpg)
Thanks,
Suphot
Hello! You have an excellent plugin, but for some reason I get the error “https://prnt.sc/QaK1vH4p9VKp” and the plugin stops “https://prnt.sc/y5Li4ajQrLKA” when there are 1000 images left to check. Perhaps it’s just one broken image that prevents the conversion from continuing, but I don’t understand how to find it. In total there are about 6000 images on the site. I will be glad for any help, thank you!
]]>Hi, I have been using the plugin for a long time and now I see that the upgrade needs PHP version 8 but my server uses 7.4 and I can’t upgrade at the moment, will it work the same?
]]>Сервер не может обработать изображение, возможно он перегружен или недостаточно ресурсов для завершения задачи. Возможно поможет загрузка меньшего размера изображения. Рекомендуемый максимальный размер – 2560 пикселов.
Загружаю 9 картинок размером 1600 пикселей
The server cannot process the image, it may be overloaded or there are not enough resources to complete the task. It might help to upload a smaller image size. The recommended maximum size is 2560 pixels.
I upload 9 pictures 1600 pixels in size
]]>Hello, is there a way that I could be sure that the “Generate Background” option, once clicked, is opened? screenshot: https://nimb.ws/adkH2p
I have a large amout of images, so I want to confirm this function is working, before receiving an email saing the task is completed.
Any suggestions?
]]>Hello. I’m sorry my english is very bad.
Processing some of the PNG images with transparency changes the background to black. Not all just some.
Original images:
https://elementorkits.nathatype.com/podsay/wp-content/uploads/sites/31/2022/06/attractive-black-teen-guy-in-casual-wear-listening-2022-01-30-08-42-49-utc_isolated.png
https://elementorkits.nathatype.com/podsay/wp-content/uploads/sites/31/2022/06/man-working-on-radio-2021-09-01-09-33-18-utc_isolated.png
https://elementorkits.nathatype.com/podsay/wp-content/uploads/sites/31/2022/06/two_phone_image.png
Version 3.0.0
quality: 85
plus-webp has a feature that automatically converts images to webp format after users upload them.
WordPress has a function that can use ctrl+v to automatically upload the picture in the clipboard when editing an article, and add the picture URL in the article. Normally, the file name of the uploaded image is image. If there is already an image named image, the image name is image-1, image-2, and so on.
If these two functions work independently, they can do a good job. But when using both functions at the same time, the bug appears.
First I uploaded an image using ctrl+v, it was named image.jpg in the media library, plus-webp converted it to webp format, named it image.webp, and automatically deleted image.jpg, which was fine.
Then when I upload a second file using ctrl+v, WordPress still names it image.jpg since image.jpg has been deleted, and that’s the problem.
Now both image.jpg and image.webp exist, so plus-webp can’t do the conversion work because the file name image.webp is already taken.
But it seems that the function of automatic URL replacement is still in effect, so in the editor, the two pictures will be displayed as the first picture.
When I uploaded the third image, because image.jpg already existed, WordPress named it image-1.jpg, and now plus-webp can convert it to image-1.webp normally, so the first The three pictures can be displayed normally in the article.
In short, this bug causes users to use ctrl+v to upload pictures, and every second picture will have a bug because it cannot be converted.
I suggest that plus-webp check if the target file name exists before converting the file, for example, before converting image.jpg, check if image.webp already exists, and if it exists, try to convert it to image-1.webp, If image-1.webp also exists, it tries to convert it to image-2.webp, and so on. This approach should solve the above problems.
Since I don’t know PHP programming language, this is just my suggestion, please forgive me if I offend you.
Finally, thank you for the plugin, it’s really nice.
]]>Hello!
I’ve run a full scan. All images pass perfectly. The description of each picture is not displayed, only some. As a result, the plugin reports success. Changing jpeg to webp does not happen.
]]>First let me say this is an excellent plugin.
During file conversion, please retain metadata (such as the title) found in uploaded file.
]]>