N
N
nyatmeat152018-08-30 12:26:46
PHP
nyatmeat15, 2018-08-30 12:26:46

How to get the mime type of an image from the base64 of an image?

Hello. Got a question. The external system returns images
in the format

iVBORw0KGgoAAAANSUhEUgA
AAAoAAAAKCAYAAACNMs + 9AAAABmJLR0QA / wD / AP + gvaeTAAAAB3RJ
TUUH1ggDCwMADQ4NnwAAAFVJREFUGJWNkMEJADEIBEcbSDkXUnfSg
nBVeZ8LSAjiwjyEQXSFEIcHGP9oAi + H0Bymgx9MhxbFdZE2a0s9kT
Zdw01ZhhYkABSwgmf1Z6r1SNyfFf4BZ + ZUExcNUQUAAAAASUVORK5
CYII =

without content type data, etc. To display such an image in the browser, you need to get the mime type from it.
How to get mime type not from a file, as php functions suggest, but from such content?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2018-08-30
@nyatmeat15

Substitute mime from any supported image format. The browser will still display the image correctly.

D
dollar, 2018-08-30
@dollar

php.net/manual/ru/function.base64-decode.php
You can check the approximate operation of the function https://www.base64decode.org/
Next, determine the first characters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question