Что не так с этим кодом?
<?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/zkeGgECBAgQIAAAQIEBLufAQIECBAgQIAAAQInFhDsJ35yPDQCBAgQIECAAAECgt3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AAQIECBAgQKAJCPbmZ02AAAECBAgQIEDgKiDYr7zOCRAgQIAAAQIECDQBwd78rAkQIECAAAECBAhcBQT7ldc5AQIECBAgQIAAgSYg2JufNQECBAgQIECAAIGrgGC/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: fatal ошибка libpng: Ошибка чтения: усеченные данные в D: \ wamp \ www \ img \ index.php в строке 5
Предупреждение: imagecreatefromstring (): ошибка gd-png: setjmp возвращает условие ошибки в D: \ wamp \ www \ img \ index.php в строке 5
Предупреждение: imagecreatefromstring (): переданные данные не находятся в формате «PNG» в D: \ wamp \ www \ img \ index.php в строке 5
Предупреждение: imagecreatefromstring (): Не удалось создать GD Image Stream из данных в D: \ wamp \ www \ img \ index.php в строке 5
Произошла ошибка.
Кто-нибудь может мне помочь, пожалуйста!
Спасибо.
В середине вашего кодированного изображения base64 есть ...
AAAECBAg...gQIECAAA
base64
данные not valid
, complete
или содержат недопустимые characters
… Вот краткая проверка
var_dump($data === base64_encode(base64_decode($data)));
Возвращает
bool(false)
$ image = imagecreatefromstring (file_get_contents ('your_image_path_here'));
Пример: $image = imagecreatefromstring(file_get_contents('sample.jpg'));