{"id":18748445,"date":"2025-12-09T09:22:42","date_gmt":"2025-12-09T09:22:42","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/image-optimization-plugin-support\/"},"modified":"2025-12-09T09:22:42","modified_gmt":"2025-12-09T09:22:42","slug":"image-optimization-plugin-support","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/image-optimization-plugin-support\/","title":{"rendered":"Image optimization plugin support"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hello<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019d like to continue a closed thread that was started at this URL: <a href=\"https:\/\/wordpress.org\/support\/topic\/webp-conversion-support\/\">https:\/\/wordpress.org\/support\/topic\/webp-conversion-support\/<\/a> <\/p>\n\n\n\n<ol>\n<li>I\u2019ve been using the Imagify plugin for several years to optimise images. The problem is that I can\u2019t get it to work nicely together with the Better Image Sizes plugin. I tried a few approaches with AI using the <code>bis_image_created<\/code> hook, but I either got no results or ended up with a 500 error. Do you know any way to make these two plugins work together?<br \/><br \/>Here\u2019s the code that doesn\u2019t work for me:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**<br \/> * Auto-optimize BIS images with Imagify after generation.<br \/> * Hooks into 'bis_image_created' to trigger Imagify optimization immediately.<br \/> *\/<br \/>if (!function_exists('wp_bis_imagify_auto_optimize')) {<br \/>  function wp_bis_imagify_auto_optimize(int $attachment_id, string $bis_file_path): void {<br \/>    \/\/ Check if Imagify is active and the class exists<br \/>    if (!class_exists('Imagify\\Optimization\\File')) {<br \/>      return;<br \/>    }<br \/>    <br \/>    \/\/ Check if file exists<br \/>    if (!file_exists($bis_file_path)) {<br \/>      return;<br \/>    }<br \/>    <br \/>    \/\/ Check if Imagify API is available and configured<br \/>    if (!function_exists('get_imagify_option') || !function_exists('imagify_valid_key')) {<br \/>      return;<br \/>    }<br \/>    <br \/>    if (!get_imagify_option('api_key') || !imagify_valid_key()) {<br \/>      return;<br \/>    }<br \/>    <br \/>    \/\/ Get Imagify settings<br \/>    $optimization_level = get_imagify_option('optimization_level', 1); \/\/ Normal by default<br \/>    $backup = get_imagify_option('backup', false);<br \/>    <br \/>    try {<br \/>      \/\/ Create Imagify File optimization instance<br \/>      $file = new \\Imagify\\Optimization\\File($bis_file_path);<br \/>      <br \/>      \/\/ Check if file can be optimized<br \/>      if (!$file-&gt;is_supported()) {<br \/>        return;<br \/>      }<br \/>      <br \/>      \/\/ Optimize the file (creates WebP\/AVIF automatically based on Imagify settings)<br \/>      $result = $file-&gt;optimize(&#091;<br \/>        'backup'             =&gt; $backup,<br \/>        'optimization_level' =&gt; $optimization_level,<br \/>        'context'            =&gt; 'custom-folders', \/\/ Mark as custom folder<br \/>      ]);<br \/>      <br \/>      \/\/ Log errors if optimization failed (optional)<br \/>      if (is_wp_error($result)) {<br \/>        error_log(sprintf(<br \/>          'Imagify BIS auto-optimization failed for %s: %s',<br \/>          $bis_file_path,<br \/>          $result-&gt;get_error_message()<br \/>        ));<br \/>      }<br \/>    } catch (\\Exception $e) {<br \/>      \/\/ Silently fail - don't break the image generation<br \/>      error_log(sprintf(<br \/>        'Imagify BIS auto-optimization exception for %s: %s',<br \/>        $bis_file_path,<br \/>        $e-&gt;getMessage()<br \/>      ));<br \/>    }<br \/>  }<br \/>  <br \/>  \/\/ Hook into BIS image creation<br \/>  \/\/ causing error 500<br \/>  add_action('bis_image_created', 'wp_bis_imagify_auto_optimize', 10, 2);<br \/>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Do I even still need Imagify, now that the <a href=\"https:\/\/wordpress.org\/plugins\/images-to-webp\/\">https:\/\/wordpress.org\/plugins\/images-to-webp\/<\/a> plugin is available? If my images in WordPress are not optimised enough, this plugin will always convert them to .webp and create a well-optimised version. Maybe the Better Image Sizes + Images to WebP setup is good enough as a solution?<\/p>\n","protected":false},"template":"","class_list":["post-18748445","topic","type-topic","status-publish","hentry","topic-tag-optimization"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18748445","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18748445\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18748445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}