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.
source share