How to use the ROS CompressedImage Encoder tool
- Select Image file and choose a JPEG or PNG no larger than 1 MB.
- Type the coordinate frame name in Frame ID, for example camera.
- Select Encode message to build the JSON.
- Copy the message from the Result box or use the Download link to save payload.json.
- Set header.stamp to a real time in your own code before publishing if subscribers depend on it.
The sensor_msgs/CompressedImage layout
CompressedImage is the standard ROS message for a camera frame that is already compressed. It has three fields: a header with a timestamp and a frame_id that names the camera's coordinate frame, a format string, and data, a uint8 array holding the complete JPEG or PNG file. Unlike sensor_msgs/Image it has no width, height or step, because a decoder reads those from the image file itself.
The encoder fills the fields as follows. format is jpeg or png according to the file's signature bytes. data lists every byte of the file as a number from 0 to 255. header.frame_id is the Frame ID text exactly as typed. header.stamp is written with sec and nanosec, the ROS 2 field names, both set to 0.
Example output for a small PNG
This is the start and end of the real output for a 70-byte PNG with the frame ID camera; the three dots mark the bytes left out here. The first eight numbers are the PNG signature. The output is indented, so each byte sits on its own line, and the full message for this tiny file has 82 lines.
{
"header": {
"stamp": {
"sec": 0,
"nanosec": 0
},
"frame_id": "camera"
},
"format": "png",
"data": [
137,
80,
78,
71,
13,
10,
26,
10,
...
66,
96,
130
]
}Limits and checks in the encoder
A numeric JSON array is a costly way to write bytes. Each one takes up to three digits plus a comma, and with indentation the text is roughly eight or nine times the size of the image. That is the reason for the 1 MB cap: a 200 KB camera frame already becomes about 1.7 MB of JSON.
- Only JPEG and PNG are encoded. GIF and WebP files are recognized but refused with Choose a JPEG or PNG image.
- Files that are not images at all give Expected PNG, JPEG, GIF or WebP bytes.
- The image may be at most 1,000,000 bytes, otherwise you see Choose an image up to 1 MB for a JSON array.
- The Frame ID is not validated and may be left empty.
- The image is not compressed again, resized or inspected beyond its signature.
Publishing the message through a JSON bridge
JSON bridges such as rosbridge wrap a message in an envelope that names the operation and topic, with the message itself under msg. Paste this tool's output as that msg value. rosbridge can take uint8[] data as a list of numbers, and also as a Base64 string, which is far more compact for large frames.
For ROS 1, rename the stamp fields to secs and nsecs, since the ROS 1 header uses those names. Then set the stamp to the capture time. Subscribers use it to order frames and to match them with other sensors, so a zero stamp is fine for a static test and wrong for a live pipeline.
Frequently asked questions
What does the format field contain?
Either jpeg or png, chosen from the first bytes of the file and not from its extension. Transport plugins sometimes write longer strings that also name the pixel encoding, so add that by hand if your subscriber expects it.
Why is data an array of numbers and not Base64?
A uint8[] field maps naturally to a JSON array, and that form needs no decoding step on the receiving side. The price is size. If your bridge accepts Base64 for byte arrays, you can put a Base64 string in data instead.
How can I check the message I built?
Paste the JSON into the ROS CompressedImage Viewer. It reads the data array, detects the image type and shows a preview, which confirms that the bytes survived intact.
Is the image sent to a server or a ROS system?
No. The page has no connection to any robot, bridge or backend. It reads the file in your browser and prints JSON.