Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to decode image-data #53

Closed
apprehensions opened this issue Sep 10, 2022 · 5 comments
Closed

how to decode image-data #53

apprehensions opened this issue Sep 10, 2022 · 5 comments

Comments

@apprehensions
Copy link

https://0x0.st/of6F.json
this is the json from tiramisu -j from https://www.bennish.net/web-notifications.html, how do i convert this to a PNG in use for a notification daemon?

@Sweets
Copy link
Owner

Sweets commented Oct 9, 2022

Apologies for the late reply.

The image data output by tiramisu is raw pixel data. So you'll first decode the base64 to a .raw file. The .raw file will need to be converted, which can be done with ImageMagick.

The appropriate information prefixes the base64 of the image. In order it's width, height, row stride, if an alpha channel is used (transparency), the bit depth, and channels.

That should point you in the right direction. If you need any additional help, let me know. I'm actually back in the US now so I can reply.

@apprehensions
Copy link
Author

apprehensions commented Oct 9, 2022

how am i even supposed to parse with jq? simply giving jq the output gives parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 2, column 18

@apprehensions
Copy link
Author

The appropriate information prefixes the base64 of the image. In order it's width, height, row stride, if an alpha channel is used (transparency), the bit depth, and channels.

I can see to decode into raw is jq -r '.hints."image-data"' | base64 -d > image.raw but since that contains the image information up until the last :, which contains the width and height, im not sure what options to pass to ImageMagick for the rest.

@Sweets
Copy link
Owner

Sweets commented Oct 9, 2022

You may not necessarily need all of the information provided. Depends on your application, but a simple image conversion should be something along the lines of magick -size WxH -depth D rgb:image.raw output.png, where W, H, and D are your width, height, and depth respectively.

Also, don't pass all of the image-data into a base64 decode. The only thing that should be passed for decoding is the actual base64 data, which is everything after the last separator (:). Some string splicing will need to be done.

Sweets added a commit that referenced this issue Oct 10, 2022
@Sweets
Copy link
Owner

Sweets commented Oct 26, 2022

This all help point you in the right direction?

@Sweets Sweets closed this as completed Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants