简体   繁体   English

在base64中导出图像

[英]export an image in base64

I want to create an image in php having the data encoded in base64 Use the code: file_put_contents('export/MyFile.png', base64_decode($img)); 我想在php中创建一个具有以base64编码的数据的图像,使用代码: file_put_contents('export/MyFile.png', base64_decode($img)); I read on the browser, but 7483 should be a larger number. 我在浏览器上阅读,但7483应该更大。 if I open the image was created only half (the other half is transparent) if the variable $img contains a short string, it works. 如果我打开图像,那么创建的图像只有一半(另一半是透明的),如果变量$ img包含短字符串,则可以正常工作。 if it contains a string too long the image will be created only partially. 如果它包含的字符串太长,则将仅部分创建图像。 why? 为什么?

PS: if I use PS:如果我使用

$img = base64_decode($img);
$fp = fopen("export/MyFile.png", "w");
fwrite($fp, $img);
fclose($fp); 

I have the exact same problems 我有完全一样的问题

thanks 谢谢

file_put_contents('export/MyFile.png', base64_decode($img));

Should be: 应该:

file_put_contents('export/MyFile.png', base64_encode($img));

If you want to encode the image, you can't use the decode function. 如果要对图像进行编码,则不能使用解码功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM