Image optimization plugin support
-
Hello
I’d like to continue a closed thread that was started at this URL: https://wordpress.org/support/topic/webp-conversion-support/
- I’ve been using the Imagify plugin for several years to optimise images. The problem is that I can’t get it to work nicely together with the Better Image Sizes plugin. I tried a few approaches with AI using the
bis_image_createdhook, 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?
Here’s the code that doesn’t work for me:
/**
* Auto-optimize BIS images with Imagify after generation.
* Hooks into 'bis_image_created' to trigger Imagify optimization immediately.
*/
if (!function_exists('wp_bis_imagify_auto_optimize')) {
function wp_bis_imagify_auto_optimize(int $attachment_id, string $bis_file_path): void {
// Check if Imagify is active and the class exists
if (!class_exists('Imagify\Optimization\File')) {
return;
}
// Check if file exists
if (!file_exists($bis_file_path)) {
return;
}
// Check if Imagify API is available and configured
if (!function_exists('get_imagify_option') || !function_exists('imagify_valid_key')) {
return;
}
if (!get_imagify_option('api_key') || !imagify_valid_key()) {
return;
}
// Get Imagify settings
$optimization_level = get_imagify_option('optimization_level', 1); // Normal by default
$backup = get_imagify_option('backup', false);
try {
// Create Imagify File optimization instance
$file = new \Imagify\Optimization\File($bis_file_path);
// Check if file can be optimized
if (!$file->is_supported()) {
return;
}
// Optimize the file (creates WebP/AVIF automatically based on Imagify settings)
$result = $file->optimize([
'backup' => $backup,
'optimization_level' => $optimization_level,
'context' => 'custom-folders', // Mark as custom folder
]);
// Log errors if optimization failed (optional)
if (is_wp_error($result)) {
error_log(sprintf(
'Imagify BIS auto-optimization failed for %s: %s',
$bis_file_path,
$result->get_error_message()
));
}
} catch (\Exception $e) {
// Silently fail - don't break the image generation
error_log(sprintf(
'Imagify BIS auto-optimization exception for %s: %s',
$bis_file_path,
$e->getMessage()
));
}
}
// Hook into BIS image creation
// causing error 500
add_action('bis_image_created', 'wp_bis_imagify_auto_optimize', 10, 2);
}2. Do I even still need Imagify, now that the https://wordpress.org/plugins/images-to-webp/ 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?
- I’ve been using the Imagify plugin for several years to optimise images. The problem is that I can’t get it to work nicely together with the Better Image Sizes plugin. I tried a few approaches with AI using the
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
You must be logged in to reply to this topic.