in reply to How to create JPEG of specified size

Just append an approriate amount of junk to the end of a real jpg that it smaller in size. The appended junk will simply be ignored be every tool, including two browsers I have tried.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: How to create JPEG of specified size

Replies are listed 'Best First'.
Re^2: How to create JPEG of specified size
by Limbic~Region (Chancellor) on Jul 25, 2007 at 16:49 UTC
    BrowserUk,
    Thanks but I do not want the junk to be ignored. In a nutshell, I need to test production like data in a development environment where the actual production data can not be used (no exceptions). Since the testing will include performance as well as functionality, the images need to be roughly the same in terms of size. I apologize but I can't be more specific about how the images are used or why I can't use the production data.

    Cheers - L~R

      I do not want the junk to be ignored.

      What does "ignored" mean? Clearly you're not expecting to do anything with the image. That sounds like a kind of ignoring.

      My suggestion would be to add bulk in the jpeg comment:

      my $jpeg = create_jpeg( height => 1, width => 1 ); save_jpeg_file( $jpeg, $file ); insert_jpeg_comment( $jpeg, ' ' x ($desired_size - (-s $file)) ); # bu +lk up the comment save_jpeg_file( $jpeg, $file ); # adjust again if necessary.

      (note - functions above are pseudo.)

      A word spoken in Mind will reach its own level, in the objective world, by its own weight
        jdporter,
        Clearly you're not expecting to do anything with the image

        I have no idea what gave you that impression. Just because I am not authorized to describe how it is going to be used or why a fake of the same physical size should be a viable substitute doesn't mean that the fake will not be processed.

        In the 5 minutes I have researched JPEG comments it appears that this indeed will be a good way of taking a tiny valid JPEG and expanding it to any desired size. Thank you. After I get it working and test it I will post a CUFP or something.

        Cheers - L~R

      The entire file will be downloaded, or loaded by whatever application you open it with.

      For example, I appended ~45K of 'AAA' to the end of the first image below using

      copy 4344.jpg/b+con junk.jpg and just holding down the A key for a few seconds.

      2005-09-19 09:47 15,996 4344.jpg 2007-07-25 16:25 60,532 junk.jpg

      When I load the first one into ifranview it tells me

      Disk size: 15.62 KB (15,996 Bytes) Memory size: 239.09 KB (244,828 Bytes) Loaded in: 15 milliseconds

      When I view the second it says:

      Disk size: 59.11 KB (60,532 Bytes) Memory size: 239.09 KB (244,828 Bytes) Loaded in: 16 milliseconds

      Also, I took the largest jpg I have (19MB) and copied it to another file twice. When I load these two I get

      18.92 MB (19,838,175 Bytes) 667.42 MB (699,840,040 Bytes) 8891 milliseconds

      37.84 MB (39,676,350 Bytes) 667.42 MB (699,840,040 Bytes) 9734 milliseconds

      So the on-disk size is just one (small) part of 'performance'.

      If this is critical, then you should be more concerned with matching the compression level, whether they are interlaced, the numbers of color table entries, and the final expansion size (essentially X x Y x depth) because these will all have a much greater impact on display time peformance, and memory usage, and the time taken to allocate the memory, than the time taken to load off disk will.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.