Why are we regenerating all image sizes on demo install?
There is this nifty plugin https://wordpress.org/plugins/force-regenerate-thumbnails/ that regenerates thumbs based on image usage not on sizes defined. We are going trough DB anyway and we should be able to know what image size is used.
I just ran the plugin and it deleted over 1500 unused images previously created on image upload

I am still testing but as you can see it checks what is used and deletes the unused ones.
How is this plugin performing this check? Only inserted images into the post editor?
I assume there are a lot of edge cases which this plugin won't be able to detect.
Im still testing , waiting for it to finish , but so far it looks ok'sh
to the post editor?
no i think it checks shortcodes,widgets,post
nah , is not checking crap , just regenerating
https://github.com/pedroelsner/force-regenerate-thumbnails
Force Regenerate Thumbnails allows you to delete all old images size and REALLY regenerate the thumbnails for your image attachments.
it deletes old ones , and creates new , that is it , I see no check utility https://github.com/pedroelsner/force-regenerate-thumbnails/blob/master/force-regenerate-thumbnails.php
man this image size restore is p... me off big time
in order to cut it im forced to deliver 200mb demo download and skip size restore , either that or have users wait 5-10 min for image sizes
Yeah, that is kind of a big problem... It pisses me off too but there really isn't any alternative to it, especially if you have a lot of image sizes
200mb of download is quite a lot and it can be bigger
Some time ago I for same issue. I needed custom (big) image sizes for really rare cases. As a solution, I wrote custom function, that on first page load check if specific image size exist and create it if not.
First page load (usually on administrator preview) was a little bit slow, but uploads folder 10 times less.
If you like this solution, I can share my code.
@sollerpolt thxn for replying , yes please share
hm , a rewritte , of it could be something like
if size does not exist show original create size
this way the load will not be slow and on next view image is there
i do that for my compression, if compressed file is there , use it if not use uncompressed and than create new file
@danyj This is my code. I recommend you to improve it by changing predefined image size to your custom value. Also code isn't perfect and can be improved.
function resize_image_for_background($image_url_id) {
$fullsize_path = get_attached_file( $image_url_id['attachment_id'] ); // Full path
$filename_only = basename( get_attached_file( $image_url_id['attachment_id'] ) );
$path_parts = pathinfo($fullsize_path);
$new_img = $path_parts['dirname'] . '/' . $path_parts['filename'] . '-1903x974.'. $path_parts['extension'];
$new_url = str_replace( $filename_only,"", $image_url_id['url']);
$new_url = $new_url . $path_parts['filename'] . '-1903x974.'. $path_parts['extension'];
if (!file_exists($new_img)) {
$image = wp_get_image_editor( $fullsize_path );
if ( ! is_wp_error( $image ) ) {
$image->resize( 1903, 974, true );
$image->save($new_img);
}
}
return 'url('. $new_url .')';
}
hm , a rewritte , of it could be something like
if size does not exist show original create size
I'm not sure this solution is better, than mine. Even on cheap servers creation of custom image size will be faster, than loading of full image (sometimes it's > 5MB).
Also in 99% of situations first page load will be triggered by site administrator/developer and really small lag not important for him.
(sometimes it's > 5MB).
true , but that is HUGE image, mine dont go over 400KB for 2560x1440, but hey you might had a real need for it.
small lag not important for him.
true but what if we are loading slider with 3 -5 images, than even dev will be pissy, but thnx for the code il see what we can make out of it
$image = wp_get_image_editor( $fullsize_path );
if ( ! is_wp_error( $image ) ) {
$image->resize( 1903, 974, true );
$image->save($new_img);
}
we have built in one ,
https://github.com/ThemeFuse/Unyson/blob/3e6aeb2799de24cbecdba3a6fa175b8cb9e2d9f6/framework/helpers/general.php#L1893
not sure which one is faster
true , but that is HUGE image, mine dont go over 400KB for 2560x1440, but hey you might had a real need for it.
But sometimes your users can upload really huge images. I personally saw site with 15MB images uploaded. I used this function for boxed post styles with image background. I need custom image size (fullHD) for speed reasons, but only for 1 of 100-200 images. So it's function allow me save disk size and make full backups really faster.
we have built in one , Tnx.
true but what if we are loading slider with 3 -5 images, than even dev will be pissy, but thnx for the code il see what we can make out of it
If your images are small, lag also will be only 0.1-0.2 sec. You need to test it.