Convert Base64 Encoding to Image in PHP

<?php 
    $str_base64 = 'R0lGODlhWABgAPcAAPL36nF1TOav';
    $str_binary = base64_decode($str_base64);
    $image = imageCreateFromString($str_binary);
    if (!$image) {
        die('Base64 value is not a valid image');
    }
    $image_file = 'images/filename.png';
    imagepng($image, $image_file, 0);
?>