How to create sketches in real time?

Is there a program or script that can read an image at standard input and write the modified image to standard output without waiting for EOF at standard input? Low quality is acceptable; waiting for the whole image to load.

ImageMagick ( convert and stream same) will read and then process and then output. What I want is more like a real-time stream processor: if I reduce 50%, it should output one line of thumbnail for every two lines of input (roughly), regardless of the state of the input stream.

If that doesn't make sense yet, imagine you are uploading an image over a slow network connection. As soon as possible, the browser starts displaying the top edge of the image. If the image is larger than the window, the browser scales it to fit the window. He should not wait for the entire image to load.

Here are some of the tools I used for testing. This serves to image the image on port 8080 in ten slices with a one second delay between slices to simulate a slow network connection:

IMAGE=test.jpg; SLICES=10; SIZE=$(stat -c "%s" $IMAGE); BS=$(($SIZE / $SLICES + 1)); (echo HTTP/1.0 200 OK; echo Content-Type: image/jpeg; echo; for i in $(seq 0 $(($SLICES - 1))); do dd if=$IMAGE bs=$BS skip=$i count=1; sleep 1; done) | nc -lp8080 -q0

Run this and immediately open localhost:8080 in your browser to see how slowly the image loads. If you apply image fragments to convert or stream instead of nc (excluding all echoes), the output will not appear within ten seconds, and then you will get all the thumbnails at once.

+4
source share
1 answer

This is difficult depending on the image format. For example, PNG is partitioned and each fragment is zlib-compressed, so you need to read in a potentially large part of the file before you can start rendering the image. BMP images are saved from bottom to top, where they are displayed from bottom right to top left, so if your thumbnail is also not BMP, you will either read the entire image or process the file back. JPEG can do this more easily; it is kept in order, and if it is a progressive JPEG, you can abuse it and read only the first N passes to get the required resolution of the thumbnails. Wavelet formats like DJVU can also be simpler.

I don’t think you will find general-purpose tools that do this, but you can write a special stream decoder specific to a specific version.

+9
source

All Articles