I made the screenshot a bit hastily, partly because trying ratpoison I can't drag things on the screen (the overlap in the shot is just a side effect) and partly because I should have installed gimp.
Anyway I realized later that I could avoid using scrot because tinycore has already screenshot.sh, I noticed that even if it creates png instead of jpg, they are smaller.
I think the compression algorithm works differently because it I noticed in the past that png even being lossy perform better than jpg with flat images. but I think that gifs from this point of view are better than both formats.
I think there was still another format that compresses even more, I think I used it for digitizing an ebook years ago.
Next I'll try your program for curiosity, what language did you write it in?