Yngvarr

Generation

generate functionFri, 25 Nov 2022

base64 save to jpg

$filename = "sample.txt"; // the name of the .txt file which contains the base64 encoded image $handle = fopen($filename, "r"); // file handler $contents = fread($handle, filesize($filename)); // read into $contents fclose($handle); // close file handler $im = imagecreatefromstring(base64_decode($contents)); // imagecreatefromstring creates an image from the string you feed it header('Content-Type: image/jpg'); // header is a function to send an HTTP header, in this case we set the Content-Type to image/jpg imagejpeg($im); // imagejpeg is a function to create a JPG file from the image created by imagecreatefromstring imagedestroy($im); // imagedestroy is a function to destroy the image, and reclaim the memory used by it

Questions about programming?Chat with your personal AI assistant