0

frankly speaking, I'm not sure if this is duplication of another question since the context should be different.

I currently working with some API that returns status & contents(binary data image) which I will base64 encode at first. The question is how to initially get the image type on it's binary data form, & after that convert it to actual image with its type extension. In this scenario, I'm using PHP since it involves with backend task. Thanks.

updates: for this case, I get the image in binary form from external site api. I use file_get_contents but it returns empty or null. When i use base64_encode then it will shows up the image as an encoded data. the issue is I need to convert it as normal image. I try getimagesize as encoded & decoded & try to print the output & it returns empty. is there any steps I am still missing?

4
  • Do you need getimagesize? Commented Jan 14, 2019 at 3:46
  • I guess no since what I need is its original image type & how to convert it back to normal image. Commented Jan 14, 2019 at 4:05
  • 1
    I think this helps... stackoverflow.com/a/49690539/2836621 Commented Jan 15, 2019 at 9:11
  • @MarkSetchell thanks buddy. I go to it first. Commented Jan 15, 2019 at 9:13

1 Answer 1

1

About your 2 questions:

how to convert it back to normal image.

If the image is simply encode with base64, then of course decode it with base64_decode got the original image data.

$original_image = base64_decode($encoded_base64_string);

I guess no since what I need is its original image type

Don't be confused by it's name, getimagesize also tells you the image type and the mime type.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for suggestion. let me try first & get back to you once get the results. Sorry for my confusion. =)
thanks buddy. Just use the base64_decode after all the try and error. I can assume the issues is solved as per my situations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.