Base64 is an encoding format that is strictly used to convert data into a text transportable format. Whatever is in that encoding format needs to be converted further if you want another format. So if you want the PNG to be a JPEG, after the Base64 decode it needs to be converted by another tool into a JPEG. This thread has some good suggestions. @Andrew Moore who answers the thread recommends using a function like this. Be sure to have the GD library installed as part of your PHP setup:
// Quality is a number between 0 (best compression) and 100 (best quality)
function png2jpg($originalFile, $outputFile, $quality) {
$image = imagecreatefrompng($originalFile);
imagejpeg($image, $outputFile, $quality);
imagedestroy($image);
}
So using your code as an example, you would then use this function to do the following:
png2jpg('myDirectory/filename.png','myDirectory/filename.jpg', 100);
Or you can deconstruct the functions of that png2jpg
function and use them in your code like this:
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
file_put_contents('myDirectory/filename.png', $data);
$image = imagecreatefrompng('myDirectory/filename.png');
imagejpeg($image, 'myDirectory/filename.jpg', 100);
imagedestroy($image);