php - Display image from imagettftext

one text

I have a code to generate a image

<?php
    ini_set('display_errors', 1);

    $members = json_decode(file_get_contents('https://discord.com/api/guilds/828207694284193802/widget.json'), true)['members'];

    $membersCount = 0;
    foreach ($members as $member) {
        if ($member['status'] == 'online') {
            $membersCount++;
        }
    }

    $img = imagecreatetruecolor(380, 80);
    $white = imagecolorallocate($img, 255,255,255);

    putenv('GDFONTPATH=' . realpath('.'));
    $font = "arial.ttf";

    $txt = "ONLINE: " . $membersCount;

    $image_width = imagesx($img);  
    $image_height = imagesy($img);

    $text_box = imagettfbbox(30,0, $font,$txt);

    $text_width = $text_box[2]-$text_box[0];
    $text_height = $text_box[7]-$text_box[1];

    $x = ($image_width/2) - ($text_width/2);
    $y = ($image_height/2) - ($text_height/2);

    imagettftext($img, 30, 0, $x, $y, $white, $font, $txt);

    header('Content-Type: image/png');

    imagepng($img);
    imagedestroy($img);
?>

And i want display a result on my forum

<img src="http://s52518.web101.svpj.pl/banners/counter_dc.php" alt="" />

But result is enter image description here

or empty box enter image description here

My PHP code working's good enter image description here

I want add the image in HTML to my sidebar/box (idk how it's name) it's a discord online users counter.

Source