I have a sample grayscale file z-gray-1x3.png, consisting of a single row of three pixels with grayscale values 0x00, 0x7f, 0xff:
I tried to write a script using imagemagick, hexdump, sed and tr but got 3-byte pixels instead:
$ magick z-gray-1x3.png -depth 8 RGB:output.txt
$ hexdump -xv output.txt | sed -E 's/^[^ ]+//' | tr -d ' \n'; echo
01017f017f7fffff00ff
(the byte 00 is padding by hexdump to an even number of digits.)
The desired output would be 007f00ff (including padding). Is there a way to modify the imagemagick command to do this?

magick z-gray-1x3.png -format "%[hex:u.p{0;0}]%[hex:u.p{1;0}]%[hex:u.p{2;0}]" info: | sed 's/\#//g'. The sed is to remove the # sign from before each hex value. This is not tested, so work with the concept. See the very bottom of imagemagick.org/script/fx.php. See also imagemagick.org/script/escape.php010101010101010101, not what I wanted. Let me try again: z-gray-1x3.png has 3 pixels. I wish to dump them to a file of 3 hex bytes. I can use the Mac application GraphicConverter to export z-gray-1x3.png to a "raw" format, consisting of just the three hex bytes. I can then dohexdump -C z-gray-1x3.rawwhose first output line includes the 3 bytes I want:00000000 01 7f ffCan Imagemagick export my image to something like GraphicConverter's "raw" format, and how?hexdump -C z-gray-1x3.gray | head -n 1 | tr -d "\147-\377" | sed 's/.\{10\}\(.*\)/\1/' | tr -d ' .'->017fff