0

I have an array bit like this:

enter image description here

Which has 763393 character length.

Then I removed [ from the start and ] from the end and also removed "," from the between of bits, now the output goes like this:

enter image description here

But now I don't know how to convert this into an actual image ?!

So if you know, please let me know...

aceraven777
  • 4,358
  • 3
  • 31
  • 55
Pouya
  • 114
  • 1
  • 8
  • 36
  • how you have created the array? Are you using `base64`? – Bhaumik Pandhi Sep 05 '22 at 04:38
  • @BhaumikPandhi I'm getting it from a json file which was written by someone else – Pouya Sep 05 '22 at 04:40
  • You need to ask them first which format they are using, we can convert the `base64` encoded string to an image (the string must have a specific `base64` encoded format.) – Bhaumik Pandhi Sep 05 '22 at 04:42
  • @BhaumikPandhi Does it have a default encoded format? Because he told me that all I need to do is to remove the **[]** and **,** then adds an image format (*.png*, *.jpg*) at the end of it but now this thing does not work out! – Pouya Sep 05 '22 at 04:51
  • before asking, do some research on the `base64` image encode/decode using PHP & Laravel. – Bhaumik Pandhi Sep 05 '22 at 04:54
  • _"Because he told me that all I need to do is to remove the [] and , then adds an image format (.png, .jpg) at the end of it "_ - then whoever told you that, apparently has little clue. The data you got there, looks like it might be individual byte values - given as integers. So the first thing to do, would be to translate those integers back into the actual byte values, using `chr`. – CBroe Sep 05 '22 at 07:46
  • @CBroe Would you mind please check this question related: https://stackoverflow.com/questions/73605779/converting-a-large-string-into-integer-by-for-loop-still-remains-as-string – Pouya Sep 05 '22 at 07:48
  • Explain how those two things are supposed to be related then? How did you get from working with an array of integers, to trying to parse one massive "string" of digits? – CBroe Sep 05 '22 at 07:51
  • @CBroe Because I have contacted with the person who gave this array of bits to me, and he gave me a python code which does the same and make an actual image from array of bits, I pasted that in this link: https://www.paste.org/122566 – Pouya Sep 05 '22 at 07:57
  • That code appears to do exactly what I suggested earlier - it converts the integers into their byte values, and then writes the whole thing to a file. `json_decode` can convert your input string into an array of values, and then you can loop over that, and use `chr` to get the corresponding byte values. – CBroe Sep 05 '22 at 08:23
  • @CBroe But `chr` expects parameter 1 to be int and array will be given, I asked a bounty question here about this: https://stackoverflow.com/questions/72413940/converting-array-bit-into-actual-image – Pouya Sep 05 '22 at 09:51
  • Quote: _"json_decode can convert your input string into an array of values, **and then you can loop over that**"_ – CBroe Sep 05 '22 at 10:32
  • But it looks like you already got a suggestion there using `pack` that should work. – CBroe Sep 05 '22 at 10:33
  • @CBroe I have updated the bounty question and tested it with pack and still the image not exported :(( https://stackoverflow.com/questions/72413940/converting-array-bit-into-actual-image – Pouya Sep 05 '22 at 11:51
  • You can't pack all numbers together. How could you tell `255 128` from `25 51 28`? Your input is possibly [JSON](https://php.net/json_decode). – Álvaro González Sep 05 '22 at 14:41

0 Answers0