尝试使用 imagecreatefromstring 保存 base64 图像,但它是全黑的
我正在尝试从数据库中获取 Base64 编码图像并将其保存到文件中。无论出于何种原因,当我尝试使用 imagecreatefromstring & imagepng 图像是全黑的。我尝试了很多不同的方法,但最终还是得到了一个黑匣子。以下是我让它发挥作用的最佳尝试。有什么想法吗?提前非常感谢!
$thefile = base64_decode($strImage);
$img = imagecreatefromstring($thefile);
if($img !== false)
{
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
}
这应该是上面的内容,但格式看起来不正确......
$strImage='iVBORw0KGgoAAAANSUhEUgAAA4QAAAD6CAYAAAD5jokXAAAMrUlEQVR4nO3dPahkZxkH8P+CkiqlaKGojcHCr9gEBBsbu5QiSRXBTksRsUijwcI0IorBD4gGGwvxC4soKLEQImiMRgMmMYmRGDbZbLJ7d++9Zy3OPd zZ2bv3zuzMnOd8/H4wxe4O8z4zmWL+ed73fRIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABG4ukkzQmPgyQXkjxcVxoAAAC78kba8HeY5OrRY//oz4vhcL+qQAAAAHanOeXfPpe2U9gFw2d6qQgAAIBeXFvhOa9F txAAAGBYTusQLlvsFr68m3IAAADoyyodwkW6hQAAABOXTodwUdctPNxiLQAAAPRo3Q7hor0cdwtf3U45AAAA9GWTQJgkP48tpAAAAKN0q1tGl9lCCgAAMDKbdggXLW4h/d0WXxCAAIAd2GYGTI63kF5L8uaWXxsAAIAt 2taW0WWHR6+9t6PXBwAAYEPb7hAuEgoBAAAGbJeBMBEKAQAABmtXW0YXCYUAAAADtOsOYUcoBAAAGJi+AmEiFAAIAAAxKn4EwEQoBAAAGo48zhMu6UHi5YG0AAACO9N0h7HSh8N9F6wMAAMxeVSBM2kDYJPl4YQ0AAACzVR kIf5DjUAgAAEDPKgNhkryWNhAeFtcBAAAwO0Pozu2lreOguhAAAIA5qe4QdvbThsKr1YUAAADMxVACYdJ2CJskF6sLAQAAmIMhBcLEJTMAAAC9GVogvJw2EL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sB0C4frmHAqbzLtDCgAAk2LsxK2Zayg0nxEAACZEILx1cwyFZjMCAMCEXI1AuIludMcb1YX0RCAEAIAJeTxtIDR4/dbNaRtl1xUFAAAmQodwM3MKSXN6rwAAMAsC4WauZj4h6Urm814BAGAWBMLNNWnD0tT9LwIhAABMikC4ublctvKbCIQAADApAuHmuttGp+6OzON9AgDAbAiEm3skbVA6X11ID5okP6ouAgAAYEjmsm20SfJSdREAAABDMpeRDHO5QAcAAGBl59OGpU9VF7Jjc+mEAgAArKVJO5dwygRCAACAE8whLM1laywAAMBa5hCW9jP99wgAALC2OcwjvJDpv0cAAIC1PZo2LJ3rcc2+ u5KP9bweAADAaFzreb1Xel7z/rSB8O09rgkAADAKfQfCijXncHkOAADA2voOZ/em/22qvz5a84M9rgkAADB4FR3CJu3tn32qeJ8AAACDtZ+6QNjnFs6fHK35iR7XBAAAGKQH0wakJsmVgvUrxl104 yfu73ldAACAQbg7x2MfmiQvFNXxl6P1P1q0PgAAwGycy/VB8KC2nCTDqQMAAGBy7svx1swhBcFO3w PqAQAAJu1Sru8Edo++b/RcxVNpa/tIdSEAAABj8r4ke2k7ficFwMMkr5ZVt7omydXqIgAAgGn5Vdqw 9LHqQjZ0IW1376TQtxwA95PcUVPMLet7/AQAADATQwsb9yY5n3bMw36Ou3tnhb3F0NcFv9/3 XPuuOEcIAADsxMW0Q9dXCVvVj8OFx0Ha0Pfk9j+SwamYRwgAAMzE+brn1Cofe0me2PUbHalf PA2E76guBAAAgP4N9RZUAAAAdmxoZz0BAADoiXOEAAAAM/VQ2kD4tupCAAAA6N+16gIAAACoIRACAADMLEAIAAAwUwIHAADATAmEAAAAMyUQAgAAzJQ5hAAAADP037SB8MvVhQAAANC/g7Sh8PHqQgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊AAAAAAAAAAAAAAAAAAAAAAAAAAACAbfo/R04U3Pjl9j8AAAAASUVORK5CYII=';
I am trying to take a Base64 encoded image from the database and save it to a file. For whatever reason, when I try using imagecreatefromstring & imagepng the image is completely black. I have tried many different approaches, but I still end up with a black box. Below is my best attempt to get it to work. Any ideas? Thank you so much in advance!
$thefile = base64_decode($strImage);
$img = imagecreatefromstring($thefile);
if($img !== false)
{
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
}
This should be above, but the formatting did not look right....
$strImage='iVBORw0KGgoAAAANSUhEUgAAA4QAAAD6CAYAAAD5jokXAAAMrUlEQVR4nO3dPahkZxkH8P+CkiqlaKGojcHCr9gEBBsbu5QiSRXBTksRsUijwcI0IorBD4gGGwvxC4soKLEQImiMRgMmMYmRGDbZbLJ7d++9Zy3OPdzZ2bv3zuzMnOd8/H4wxe4O8z4zmWL+ed73fRIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABG4ukkzQmPgyQXkjxcVxoAAAC78kba8HeY5OrRY//oz4vhcL+qQAAAAHanOeXfPpe2U9gFw2d6qQgAAIBeXFvhOa9FtxAAAGByTusQLlvsFr68m3IAAADoyyodwkW6hQAAABOxTodwUdctPNxiLQAAAPRo3Q7hor0cdwtf3U45AAAA9GWTQJgkP48tpAAAAKN0q1tGl9lCCgAAMDKbdggXLW4h/d0WXxcAAIAd2GYgTI63kF5L8uaWXxsAAIAt2taW0WWHR6+9t6PXBwAAYEPb7hAuEgoBAAAGbJeBMBEKAQAABmtXW0YXCYUAAAADtOsOYUcoBAAAGJi+AmEiFAIAAAxKn4EwEQoBAAAGo48zhMu6UHi5YG0AAACO9N0h7HSh8N9F6wMAAMxeVSBM2kDYJPl4YQ0AAACzVRkIf5DjUAgAAEDPKgNhkryWNhAeFtcBAAAwO0Pozu2lreOguhAAAIA5qe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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAbfo/R04U3Pjl9j8AAAAASUVORK5CYII=';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 imagepng() 之前调用 imagesavealpha()
Call imagesavealpha() before your imagepng()