For a network experiment I am conducting, I require image files of arbitrary size.
I am lost on how to create such files. I require 5MB, 10MB and 20MB files in JPEG, PNG and PDF format.
In my first attempt at generating these files it became clear that due to the compression schemes of these formats, it's not possible (or at least I don't know how) to generate files of arbitrary size by just specifying resolution of blank files.
Is there a quick (programmatic?) method by which I could generate these files?
Edit: I am investigating creating arbitrarily sized dummy files, but if there is a way to create actual JPEG, PNGs or PDFs that have the correct internal format, that would be ideal.
There are two commands you can enter in the Command Prompt to create a dummy file: fsutil file createnew filename size. fsutil file createnew pathfilename size.
This is just a suggestion. No idea if it will work.
Perhaps you could generate bitmaps at the correct size and convert them?
If you make the bitmaps very hard to compress(1)? You should then be able to convert them to jpg and png very close to the target size.
(1) My suggestion is that this might be achieved by making each pixel in the bitmap a different colour (as far as possible)
Edit:
This simple solution probably does not work for jpg's, but at least png's seems to work.
I hacked together a small testapp in c# to try it out. Here is the meat of it:
private void make_bitmap(int width, int height)
{
Random random = new Random();
Bitmap B = new Bitmap(width, height);
int redvalue = 0;
int greenvalue = 0;
int bluevalue = 0;
bool pick_random_color = true;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < width; y++)
{
Color col;
if (pick_random_color)
{
col = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
}
else // iterate over all colours repeatedly
{
if (redvalue == 255) { redvalue = 0; greenvalue++; } else { redvalue++; }
if (greenvalue == 256) { greenvalue = 0; bluevalue++; }
if (bluevalue == 256) { redvalue = 0; greenvalue = 0; bluevalue = 0; }
col = Color.FromArgb(redvalue, greenvalue, bluevalue);
}
B.SetPixel(x, y, col);
}
}
B.Save("image.bmp");
B.Save("image.jpg", ImageFormat.Jpeg);
B.Save("image.png", ImageFormat.Png);
B.Dispose();
}
Do the files need to be JPEG format internally, or just arbitrary binary files named JPEG? If the latter, see this Stack Overflow answer:
Creating a Huge Dummy File in a Matter of Seconds in C#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With