此代码有什么问题?
<?php
$data = "iVBORw0KGgoAAAANSUhEUgAAAuwAAAUeCAYAAAAl3WRgAAAgAElEQVR4Xuzdz6/vCV3f8TPADIozowg1ETZ2U2Chm6oLuqkdE1clSlzVdEhXLuAPKPwB1X110ZWBpqyMGLoiAe3KRa2bshDclE0xqSDlp4woej5nPJczd+bOmTmv+2Q+d+ZxEkPC3Pfrfs/je0ye8+V7v/exn/rNL/zDhS8CBAgQIECAAAECBE4p8JhgP+Xz4kERIECAAAECBAgQuBIQ7H4QCBAgQIAAAQIECJxYQLCf+Mnx0AgQIECAAAECBAgIdj8DBAgQIECAAAECBE4sINhP/OR4aAQIECBAgAABAgQEu58BAgQIECBAgAABAicWEOwnfnI8NAIECBAgQIAAAQKC3c8AAQIECBAgQIAAgRMLCPYTPzkeGgECBAgQIECAAAHB7meAAAECBAgQIECAwIkFBPuJnxwPjQABAgQIECBAgIBg9zNAgAABAgQIECBA4MQCgv3ET46HRoAAAQIECBAgQECw+xkgQIAAAQIECBAgcGIBwX7iJ8dDI0CAAAECBAgQICDY/QwQIECAAAECBAgQOLGAYD/xk+OhESBAgAABAgQIEBDsfgYIECBAgAABAgQInFhAsJ/4yfHQCBAgQIAAAQIECAh2PwMECBAgQIAAAQIETiwg2E/85HhoBAgQIECAAAECBAS7nwECBAgQIECAAAECJxYQ7Cd+cjw0AgQIECBAgAABAoLdzwABAgQIECBAgACBEwsI9hM/OR4aAQIECBAgQIAAAcHuZ4AAAQIECBAgQIDAiQUE+4mfHA+NAAECBAgQIECAgGD3M0CAAAECBAgQIEDgxAKC/cRPjodGgAABAgQIECBAQLD7GSBAgAABAgQIECBwYgHBfuInx0MjQIAAAQIECBAgINj9DBAgQIAAAQIECBA4sYBgP/GT46ERIECAAAECBAgQEOx+BggQIECAAAECBAicWECwn/jJ8dAIECBAgAABAgQICHY/AwQIECBAgAABAgROLCDYT/zkeGgECBAgQIAAAQIEBLufAQIECBAgQIAAAQInFhDsJ35yPDQCBAgQIECAAAECgt3P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AQIECBAgQKAJCPbmZ02AAAECBAgQIEDgKiDYr7zOCRAgQIAAAQIECDQBwd78rAkQIECAAAECBAhcBQT7ldc5AQIECBAgQIAAgSYg2JufNQECBAgQIECAAIGrgGC/8jonQIAAAQIECBAg0AQEe/OzJkCAAAECBAgQIHAVEOxXXucECBAgQIAAAQIEmoBgb37WBAgQIECAAAECBK4Cgv3K65wAAQIECBAgQIBAExDszc+aAAECBAgQIECAwFVAsF95nRMgQIAAAQIECBBoAoK9+VkTIECAAAECBAgQuAoI9iuvcwIECBAgQIAAAQJNQLA3P2sCBAgQIECAAAECVwHBfuV1ToAAAQIECBAgQKAJCPbmZ02AAAECBAgQIEDgKiDYr7zOCRAgQIAAAQIECDQBwd78rAkQIECAAAECBAhcBQT7ldc5AQIECBAgQIAAgSYg2JufNQECBAgQIECAAIGrgGC/8jonQIAAAQIECBAg0AQEe/OzJkCAAAECBAgQIHAVEOxXXucECBAgQIAAAQIEmoBgb37WBAgQIECAAAECBK4Cgv3K65wAAQIECBAgQIBAExDszc+aAAECBAgQIECAwFVAsF95nRMgQIAAAQIECBBoAoK9+VkTIECAAAECBAgQuAoI9iuvcwIECBAgQIAAAQJNQLA3P2sCBAgQIECAAAECVwHBfuV1ToAAAQIECBAgQKAJCPbmZ02AAAECBAgQIEDgKiDYr7zOCRAgQIAAAQIECDSBAaWRPdih0+LkAAAAAElFTkSuQmCC";
$data = base64_decode($data);
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
?>
我收到这些错误:
警告:imagecreatefromstring():gd-png:致命的libpng错误:读取错误:第5行的D:\ wamp \ www \ img \ index.php中的截断数据
警告:imagecreatefromstring():gd-png错误:setjmp在第5行的D:\ wamp \ www \ img \ index.php中返回错误条件
警告:imagecreatefromstring():第5行的D:\ wamp \ www \ img \ index.php中传递的数据不是'PNG'格式
警告:imagecreatefromstring():无法在第5行的D:\ wamp \ www \ img \ index.php中使用数据创建GD图像流
发生错误。
有人可以帮助我吗?
谢谢。
答案 0 :(得分:6)
base64
数据为not valid
,complete
或包含无效characters
...这是一个快速验证
var_dump($data === base64_encode(base64_decode($data)));
返回
bool(false)
答案 1 :(得分:5)
在base64编码图像的中间有一个...
。
AAAECBAg...gQIECAAA
答案 2 :(得分:0)
$ image = imagecreatefromstring(的file_get_contents(&#39; your_image_path_here&#39;));
示例:$image = imagecreatefromstring(file_get_contents('sample.jpg'));