Title: Optimise dynamically generated thumbnails?
Last modified: March 14, 2021

---

# Optimise dynamically generated thumbnails?

 *  Resolved [smerriman](https://wordpress.org/support/users/smerriman/)
 * (@smerriman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/optimise-dynamically-generated-thumbnails/)
 * I am using (as an example) a custom block where you provide an image and it generates
   a thumbnail on save, with rough code along the following lines:
 *     ```
       $file = get_attached_file($id);
       $editor = wp_get_image_editor($file);
       if ( ! is_wp_error( $editor ) ) {
           $sizes = $editor->multi_resize(array('newsize'=>array('width'=>240,'height'=>240,'crop'=>true)));
           $meta['sizes'] = array_merge($meta['sizes'],$sizes);
           wp_update_attachment_metadata($id,$meta);
       }
       ```
   
 * I don’t want to use `add_image_size` and have it generate this size for every
   single image uploaded to the site, only this specific one.
 * Is there a way to tell LiteSpeed to optimise it, without needing to rescan the
   entire site manually to look for missing thumbnails?
 * Could I manually add the image to the litespeed_img_optm table, or is there a
   function I could call?
    -  This topic was modified 5 years, 1 month ago by [smerriman](https://wordpress.org/support/users/smerriman/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [smerriman](https://wordpress.org/support/users/smerriman/)
 * (@smerriman)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/optimise-dynamically-generated-thumbnails/#post-14181136)
 * Just to be precise, the image already gets added to the table (when you upload
   it). But the dynamic thumbnail does not.
 * And the rescan process takes a long time with a large site, so just looking for
   a quick workaround to get just one specific thumbnail in the queue.
 *  Plugin Support [Hai Zheng⚡](https://wordpress.org/support/users/hailite/)
 * (@hailite)
 * [5 years ago](https://wordpress.org/support/topic/optimise-dynamically-generated-thumbnails/#post-14202656)
 * At the initial thinking, I think you can directly insert those data into img_optm
   table, make a similar function like `_save_raw()`.
 * Later on, I realized this is a good case to improve the image gathering process.
 * Therefore, this part is improved in v3.7-rc25 ([https://github.com/litespeedtech/lscache_wp/commit/41fa5a7882f2ee6e49e94c1fda186d3fe1beab8b](https://github.com/litespeedtech/lscache_wp/commit/41fa5a7882f2ee6e49e94c1fda186d3fe1beab8b)).
   Please give it a try. You don’t need to do any extra operation as we hooked the
   function `wp_update_attachment_metadata`.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Optimise dynamically generated thumbnails?’ is closed to new replies.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Hai Zheng⚡](https://wordpress.org/support/users/hailite/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/optimise-dynamically-generated-thumbnails/#post-14202656)
 * Status: resolved