Is it possible to dynamically include the gd2 functionality in PHP without recompiling?

The gd2 functionality in PHP can be dynamically included without recompiling by installing the GD extension through PECL. This allows you to enable GD support without the need to recompile PHP.

if (!extension_loaded('gd')) {
    if (version_compare(PHP_VERSION, '7.2.0', '<')) {
        dl('gd.so');
    } else {
        dl('gd2.so');
    }
}