setImageFormat( 'webp' ) ) { $img->setImageCompressionQuality( 80 ); $img->writeImage( $webp_path ); $img->clear(); $img->destroy(); if ( file_exists( $webp_path ) ) { return $webp_path; } } } catch ( \Exception $e ) { // ignore and fall back to PNG } } return $png_path; } }