tags:

views:

25

answers:

2

I want to create arbitrary sized pngs and jpeg images of a single block colour at a specified x,y size, however I do not want to do this by generating a raw image in memory and encoding/compressing it due to potential memory requirements.

How would this be done?

+1  A: 

You could make your own generator. Pseudo-code for a PNG generator is:

write_png_header(width,height);
gzip_scanline(width,colour);
for(y=1; y<height; y++) { // scanline 0 already written
  write_type_copy_previous();
  gzip_zero_delta(width);
}
Will
+1  A: 

It's unclear what language you're using, or what your use case is, but I use the convert program from the imagemagick suite to do this:

convert -size 300x300 xc:transparent missing_normal.png

If you're creating images for a browser you could just create a single 1x1 image, then use the width and height attributes to let the browser scale it for you.

Jeff Paquette
I can use c# java c c++
Tom J Nowell
Nopa good suggestion but it preallocates the necessary space in memory, so for very big images it wouldnt be very nice =(
Tom J Nowell
Doing some testing on cygwin, convert's memory usage is stable. It used no more memory for a 100000x100000 image than it did for a 10000x100000 image. Smaller images were created faster than I could see the memory usage.
Jeff Paquette
hmmm, well I tried a 19k by 19k and my computer ground to a halt, I had to close the program and then it was almost 20 minutes before everythign started responding correctly again
Tom J Nowell