In reference to a private message, Limbic~Region, it sounds like you're more interested in bulking up the file to emulate a large download or a large disk load. There are some thoughts about this.

If jpg is your target format, bulking it up on disk is easy: write a simple small .jpg file, then append as much random binary garbage that you want after it. This will satisfy your desire to make the file bigger without having to go through some tedious guesstimate loop that makes more PIXELS to satisfy the requirements of more BYTES.

If your intent is to create a larger download, either for stress testing your system or for poisoning a bandwidth hog, then this is a bit trickier: I don't think any browsers are smart enough to parse the jpg as it reads it (and stops when it reaches the end of valid jpg data), but theoretically one could. If you give a 1x1 pixel image with a megabyte of junk following, the jpg parser could stop after the first hundred bytes and not bother reading or downloading the rest. You'd have to do some tests to ensure you're seeing that the whole thing is getting downloaded.

If someone's leeching your bandwidth by deeplinking your jpg on your server, and you replace it with a surrogate, I suggest NOT inflating the file to hurt the downloader, since you're ultimately paying the bandwidth on your side too. Make a 1x1 or a highly-compressed "bandwidth hog" image to replace the original.

With GD or ImageMagick, if you want to make more PIXELS to make a genuine image that happens to require more BYTES (disk or memory), then I suggest you create a small original, then use these APIs to create a "stretched" equivalent of it at larger dimensions. This will ensure the jpg parser must read the whole thing. An image that is all-white or all-red, like the previous examples, will compress VERY well, so you will have a lot of PIXELS that don't take much disk space.

--
[ e d @ h a l l e y . c c ]


In reply to Re^2: How to create JPEG of specified size by halley
in thread How to create JPEG of specified size by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.