loadHTML($html); // Get the element from the URL $getImage = $dom->getElementsByTagName('image'); // Check if User has bitmoji if($getImage->length==0){ die('User does not have Bitmoji.'); } // Loop through the Images & grab the 'xlink:href' attribute foreach($getImage as $img){ $bitmojiData = $img->getAttribute('xlink:href'); } // Replace the beginning to convert to Base64 $base64 = str_replace('data:image/png;base64,', '', $bitmojiData); // Decode the Base64 so we can flop it into a PNG $base64 = base64_decode($base64); // Create an image from $base64 $bitmoji = imagecreatefromstring($base64); if ($bitmoji !== false) { // Change the Script Content-Type to image/png so it can be used throughout the internet header('Content-Type: image/png'); // Make sure to keep the Alpha set to true, unless you want a black background imagesavealpha($bitmoji, true); // Create the PNG imagepng($bitmoji); // Free up some memory imagedestroy($bitmoji); } else { echo 'An error occurred.'; } } else { echo 'Snapchat username must be set!'; } ?>