Greetings,
I recently used your plugin to compress PNG images on my website, and I must say, it worked perfectly and saved me a great deal of time.
However, one feature I found missing��and ended up adding myself��was the ability to sort images by file size. I didn��t want to process all images, only the larger ones, so being able to sort by size made it much easier to identify large files and convert them to JPEG.
Here��s the code I added, which you can incorporate into your plugin. If you have a Git repository, I��d be happy to contribute directly there, but unfortunately, SVN doesn��t work for me. Otherwise, feel free to add it yourself��I believe it��s a feature many others would find useful.
To begin, add id to the table
<table id="JpgToPngTable" class="wp-list-table widefat striped media">
Replace <th> for the file size with
<th onclick="sortTable(2)" class="sortable sorted">
<a href="#">
<span><?php _e('Filesize', 'png_to_jpg') ?></span>
<span class="sorting-indicators">
<span class="sorting-indicator asc" aria-hidden="true"></span>
<span class="sorting-indicator desc" aria-hidden="true"></span>
</span>
</a>
</th>
JS Function to sort by size
function sortTable(columnIndex, event) {
const table = document.getElementById("JpgToPngTable");
const rows = Array.from(table.rows).slice(1); // Exclude the header row
const headers = table.querySelectorAll("th"); // Get all headers
const currentHeader = headers[columnIndex]; // Get the header for the clicked column
let ascending = currentHeader.getAttribute("data-sort-asc") === "true"; // Track sorting direction from th
// Remove focus from the <a> element after the click
if (event && event.target && event.target.closest("a")) {
event.target.closest("a").blur();
}
// Helper function to convert file size strings to bytes
function fileSizeToBytes(sizeStr) {
const size = parseFloat(sizeStr); // Extract the numeric part
const unit = sizeStr.replace(/[0-9.]/g, '').trim().toUpperCase(); // Extract the unit (KB, MB, etc.)
switch (unit) {
case 'KB':
return size * 1024;
case 'MB':
return size * 1024 * 1024;
case 'GB':
return size * 1024 * 1024 * 1024;
default:
return size; // In case no unit is present or unrecognized (assume bytes)
}
}
// Sort rows based on the clicked column (file size conversion)
rows.sort((rowA, rowB) => {
const cellA = rowA.cells[columnIndex].innerText.toLowerCase();
const cellB = rowB.cells[columnIndex].innerText.toLowerCase();
const sizeA = fileSizeToBytes(cellA);
const sizeB = fileSizeToBytes(cellB);
return ascending ? sizeA - sizeB : sizeB - sizeA; // Compare sizes numerically
});
// Append sorted rows back to the table
rows.forEach(row => table.tBodies[0].appendChild(row));
// Remove any previously added 'asc' or 'desc' class from all headers
headers.forEach(header => {
header.classList.remove("asc", "desc");
header.removeAttribute("data-sort-asc"); // Clear the sort order attribute for other headers
});
// Add 'asc' or 'desc' class based on the sorting direction
if (ascending) {
currentHeader.classList.add("asc");
currentHeader.classList.remove("desc");
} else {
currentHeader.classList.add("desc");
currentHeader.classList.remove("asc");
}
// Toggle sorting direction for the clicked column
currentHeader.setAttribute("data-sort-asc", !ascending);
}
]]>
When I go to convert existing tab after setting. I select all png and then click on convert selected png, it says done but its not done actually.
PLEASE HELP. I tried everything, cache clear, etc.
I am using rey theme with woocommerce
]]>Hi, Ive tried a few plugins to try and convert PNGs to JPGs on our woocommerce ecom site, this one seems the best but its not quite working for me.
We imported about 300 products recently from a suppliers website and they were using PNGs for most of their images (hopeless…). When I convert images using your plugin they dont show up on the product, its still using all the PNG files. If I then go to edit the product and save it, it will then get all the images correctly.
Is this because a database field isnt being updated by your plugin? Only when I actually edit/update the product are those fileds saved.
]]>I’m loving your plugin! It’s working great for me with the media library, posts and pages. But I’ve just noticed it’s not working with my custom post types and slider plugin (Slide Anything and Metaslider). When you upload an image via the content editor in these places it doesn’t seem to be triggering the auto convert. I think I remember reading about this in your documentation, but can’t find it now. Is there a filter (or similar) I can add to functions.php to get it working with CPTs and other content types? Any help much appreciated.
]]>When PNG to JPG works it works great! It doesn’t always work, especially when converting large quantities of PNGs on crusty old sites. And so I’m looking for a way to convert images on more of a one-on-one basis. Can you help with this?
I’d like to be able to convert the most egregious PNGs (e.g. a 19 megabyte no-transparency monster someone uploaded to a client site.)
There are 2000+ PNGs on this client’s site so paging through to find the really bad ones is time consuming.
Request: Either a way to
Hi,
Thanks for your plugin. It very useful ??.
I use Pods Framework for many website. I use it to create Custom Post Type and Custom Setting. I add Image/Gallery custom Field to CPT and Custom Setting by Pods.
Can you add support for Pods. I need convert png images to jpg in Pods Image/Gallery Custom Fields.
Thanks ??????
]]>After converting all my images Facebook share now shows a blank image.
What can be done to fix this?
]]>Hello,
This is a great plugin! I have thousands of PNG images – But PNG2JPG only converted 600 images, then brought a server error. The remaining images don’t appear anymore in the “convert existing PNGs” tab.
Is there a way to force reevaluation of PNG images to reprocess?
Thanks
]]>Hi,
Thank you for your extension.
There is a warning with PHP 8.2 :
Deprecated: Creation of dynamic property png_to_jpg::$db_tables is deprecated in \wp-content\plugins\png-to-jpg\png-to-jpg.php on line 150
Can you correct this please?
Thanks,
Cordially,
Stephan
Hi, when attempting to convert an existing PNG to JPG, I receive this error message:
Your server is not powerful enough to process image [redacted].png
Is there a setting in the site or on the server to resolve this? Thank you.
]]>Hi,
I’m trying to delete backup /original images from my server. I no longer want to keep them.
]]>It would be awesome when this plugin also supported the wp
CLI, especially when processing lots of images in an automated fashion.
I noticed this recreates thumbnail sizes that I had already deleted.
Can I stop it doing that?
My objective here is to shrink my Media Library. So I have already used other optimisation tools, including deleting most of the multiple image sizes WordPress creates for each image.
Does the plugin basically do what WordPress says, generate each thumbnail?
Should I, therefore, use a plugin or code to stop this? https://hamzashatela.com/three-ways-disable-wordpress-creating-thumbnails/
]]>Hi,
I’ve got a bunch of images that were ‘converted’ which meant the image URL was updated from PNG to JPG but the actual JPG file was never created. I can’t find it in the upload folder and on pages its used it will show a 404 missing img.
Any thoughts?
]]>Hi!
I’ve monkey patched the fail method of the ajax call on my server to this:
}).fail(function(er){
console.log( 'Your server is not powerful enough to process image ' + $.trim( $tr.find('.filename').text() ), er );
$el.prop('checked', false);
if( stopPNGtoJPG ){
$('#transparency_status_message').html('<p><?php _e('Done') ?>.</p>');
$('tbody tr input').prop('disabled', false);
}else{
delete_selected_pngs();
}
});
This is beneficial for converting large amount of images, because I want the conversion to continue, just because one or two images fail. However in the plugin version the admin page need to be reloaded after a failure and also the selection have to be made again. Can take very long time and needs human overview during the process.
Another suggestion is to add window.stopPNGtoJPG = false;
to $('.convert-pngs').click(function(event) {
, so the processing can be started again even after stopped without reloading the page.
Thanks for the plugin indeed!
]]>I created lots of .png files just so I could have dropped shadows and would be visible/transparent on all background colors.
1. By changing .png to .jpg does the drop shadow effect go away?
2. On the ones converted to .jpg will they now have a white background?
I no longer use any background color other than white, so I need to know if the converted .jpg files will look okay on my “all white” background before I commit to applying the changes.
Thanks for any and all help.
]]>Hello, on the wordpress blog I work on there are approx 10k png’s that really should be jpg’s, and in researching this project I came across this plugin, which seems like it might help. The only trouble is it looks like it is trying to display all 10k images at once on the ‘Convert Existing PNGs’ page, which is leading to lots of timeouts. I wonder if there is a way to set up the plugin so that I can convert maybe only 100 or so images at a time, and then once that is complete, move on to the next 100? Thanks so much for this plugin!
]]>Hello, Jakub,
Congratulations, this plugin is very straightforward and performs lovely, even when analysing +55.000 images.
I have noticed the following error in the wp-admin error log:
[24-Mar-2022 00:32:37 UTC] WordPress database error Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_unicode_ci,COERCIBLE) for operation 'like' for query
UPDATE wp_revslider_static_slides
SET layers = REPLACE( layers, '/pove?tile-bucure?tiului-curs-?n-4-?ntalniri-550x468.png', '/pove?tile-bucure?tiului-curs-?n-4-?ntalniri-550x468.jpg')
WHERE layers LIKE '%/pove?tile-bucure?tiului-curs-?n-4-?ntalniri-550x468.png%'
made by do_action('wp_ajax_convert_old_png'), WP_Hook->do_action, WP_Hook->apply_filters, png_to_jpg->convert_old_png, png_to_jpg->update_image_data
While I don’t think this error is an issue for us, as I’m converting old images that are no longer used in the revolution slider, perhaps you want to know about it.
Kind regards,
Cristina.
Does this plugin also change the address of images in content and thumbnails so that there is no need to modify the address manually?
I need the plugin to automatically replace images throughout the site. Including content, thumbnail, images of WooCommerce products and its gallery
]]>Hello,
I like your plugin and have a question:
have you planned an update to wordpress 5.9?
Regards
Rainer
Hi,
I read this and have a question..
If I convert my pngs to jpg will the product image then serve the jpg image to users? And then can I delete the pngs?
https://www.ads-software.com/support/topic/works-for-woocommerce-products-as-well/
]]>Hi, tks for the plugin, it is just awesome ??
But I saw it adds a show table query through init causing a slow query. Please, test Query Monitor plugin with your plugin on and you will see it. Please, let me know if something can be made about it. Tks! ??
Hello,
First of all thank you for your plugin.
I’ve tried to bulk png to jpg. But after waiting several minutes. It only done to some of my images. The rest is left with code “0” on “Has Transparancy” not NO/YES.
What is that mean and how to fix it?
Thank you
]]>After clicking “Convert selected PNGs”, there’s no way to cancel the operation without closing the browser window. This is frustrating, because I sometimes spend a long time checking hundreds of images, then after starting the operation I notice an image I shouldn’t have checked. I want to be able to stop the conversion process while keeping my selections checked. Can you add this feature? Thanks!
]]>Hi Thanks png to jpg worked for me, my uploads folder was 4.5gb it is now half that. I am using WP version: 5.7.2, Divi, Divi Extra. My bandwidth had gone crazy due to 8+mb png featured images being uploaded for months. I had success cleaning the site locally in MAMP first with MediaCleaner Pro then PNG to JPG the processes take hours to run but work perfectly if patient. Do not let your computer sleep during the process. Run the plugin multiple times until complete. Look at the developer window in Chrome to see errors while converting or if the plugin has hung. I am sharing this because I have wasted days and cash with SmushPro and WPMU DEV trying to do this on a live staging site.
]]>Hello,
I want to exclude some images forever. Like my logo, footer items, menu category icons etc.
So they will not converted to jpg by mistake.
Can you add this feature?
]]>Hi,
Recently tested your plugin.
looks great but unfortunately doesn’t really work so well.
I had a png that i wanted to convert to a jpg.
I ran the conversion with the plugin for the single file.
it was in /uploads/2020/10/
the jpg was however created in /uploads/2021/01/
Also I noticed that for the post referencing the file (was set as a featured image), this was still referencing the old png file, so the database update hasn’t worked in this case.
So I just wanted to report these bugs, hopefully its helpful.
]]>Hey, I’ve tried your plugin, but I notice my photos become much darker and duller after conversion. Is there something I/you can do about it? In the current state this is not acceptable for the images of the products on the webshop. But we have >1000 png’s that need to be converted, so your solution would be perfect. Unfortunately I can’t upload a photo here to show you the before and after.
]]>In the setting option we can choose the quality of jpg image so it mean jpg will be compressed . So which type of compressed you use in this plug in? Lossy or lossless , jpegtran, jpegoptim, mozjpeg…….
Is this plugin only convert png to jpg when I set quality is 100 or you use lossless for 100% quality?
]]>Hi
please add “GIF” images format to be converted to JPG as well.
so it will be PNG,GIF to JPG
regards
]]>