Convert any file (raw data) to png? Use png as zip basically

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
steveyjg

Convert any file (raw data) to png? Use png as zip basically

Post by steveyjg »

Is it possible to convert any file (text, pictures, audio, video, any data) to a png? So basically png image compression would be used as data compression, png instead of zip. The outputted png image would be look scrambled since it has the bytes of the original file stream arranged into a png.

Code: Select all

convert data.dat output.png
won't work because ImageMagick tries to read the headers of data.dat which doesn't have image headers. Is this encoding (compression) possible? Are certain parameters needed?

Equally important would the decoding (decompression) of the png back to the data file be possible? With the syntax

Code: Select all

convert output.png data.dat
plus some parameters probably. Somehow the original file name ("data.dat") would have to be encoded into the png as well.

If ImageMagick can't do this is there another program that can?

EDIT: I'm mainly talking about png due to its lossless compression but if this could done with a jpg that would be interesting.
Last edited by steveyjg on 2008-12-21T17:19:12-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Convert any file (raw data) to png? Use png as zip basically

Post by magick »

You can do what you want with a raw image format such as gray:
  • convert -size 10000x1 gray:image.dat image.png
    convert image.png gray:image.dat
You can also choose the depth of your raw data with -depth (i.e. -depth 16).
steveyjg

Re: Convert any file (raw data) to png? Use png as zip basically

Post by steveyjg »

Thanks magick! The dimensions of the png greatly affect how well the conversion goes though. If its too big then theres a bunch of dead space at the end; too small and a png sequence occurs. I wish there was a way to automatically calculate the needed dimensions for the total bytes but thanks again magick.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert any file (raw data) to png? Use png as zip basically

Post by anthony »

The size represents how many data samples IM is to read from a raw data stream. So just get the byte size of the raw data file to use for that number.

NOTE a audio signal most likely consists of signed values, while images are unsigned values. As such the image may not represent the data unless you add (using Modulus Addition) a 50% bias to the result. If you want to get a nicer image representation "-compose add -compose" a perfect gray (color of "gray50") image of the same size.

Such an 'bais normalized' image may also compress better as the signal will be a more continuous wave form. You may even be able to use a lossy JPEG compress and still recover a reasonable audio quality in the reverse process (purely for raw data, no headers or other encoding present).

And PLEASE report back what works and the things you learnt from the exercise.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply