Yeah, there’s no WP-CLI commands in Imsanity, but there are in my other plugin, the EWWW Image Optimizer, which has the same resizing options. I’ve never tried it for just resizing, but you could set the compression to lossless which will save you a little more space than just pure resizing.
Let me suggest a simple refactor like this:
function imsanity_resize_image()
{
imsanity_verify_permission();
global $wpdb;
$id = (int) $_POST['id'];
$results=imsanity_resize_image_id($id);
die( json_encode( $results ) );
}
I could, but to what end? So you can use the imsanity_resize_image_id() function via WP-CLI’s eval command? Then you still have to get a list of attachment IDs, write a script to run eval a bunch of times (or send one really long bit of PHP to the eval command).
Why not just use EWWW IO’s WP-CLI command and be done with it?
You’re right!
EWWW is perfect for the job.
I’ll leave this code for anyone who needs it:
# how to install required packages in ubuntu 16
sudo apt-get update && sudo apt-get install -y libjpeg-progs imagemagick php-imagick graphicsmagick gifsicle
# run wp command, if not installed, install it in http://wp-cli.org/
wp ewwwio optimize media --skip-themes