4

When on travel.state.gov's photo editor, I get

Image is overly compressed. Please use a compression ratio that is less than 20:1

Is there anyway to get past this screen in the application given a jpg file? Can I open it up in a gimp and make less-compressed knowing the quality won't be better?

Evan Carroll
  • 8,863
  • 17
  • 76
  • 129
  • compression ratio may be a *red herring*: include the pixel dimensions of your failed upload in your question. FYI passport photos are 2x2 inches, which is 600x600 pixels if printed at 300 ppi. No need for the image you upload to be larger than that. – Yorik Oct 14 '21 at 15:29

2 Answers2

4

the tldr: in Chrome you open up the developer console (Ctrl + Shift + J) and run,

MAX_COMPRESSION_RATIO = Infinity

We can devise two ways to do this (1) by editing the image, or (2) by editing the JavaScript code.

How it works

Looking at the code, you can see how it's calculated from the definition of

function getCompressionRatio(e, t) {
    return 3 * e.naturalWidth * e.naturalHeight / t
}

And the call site,

var e = getCompressionRatio(image, imageNumBytes);

So in the definition e is image and t is imageNumBytes. This is the assumption that the raw image is 3 bytes-per-pixel (TrueColor).

function getCompressionRatio(image, imageNumBytes) {
    return 3 * image.naturalWidth * image.naturalHeight / imageNumBytes
}

Our options

  1. Editing the JavaScript code: Alternatively this error is rendered here,

    if (MAX_COMPRESSION_RATIO < e)
        setUI(UIModeEnum.INIT),
        setMessageDialog("Your photo has been rejected for the following reason(s):", [{
            description: "Image is overly compressed. Please use a compression ratio that is less than 20:1"
        }]),
        showControls(!0, ["divMessages"]);
    

    In Chrome you can open up the developer console (Ctrl + Shift + J) and run,

    MAX_COMPRESSION_RATIO = Infinity
    

    And then the conditional will never trigger and you won't get that error.

  2. Editing the image: In order to get a lower "compression ratio" for your image you need only lower the numerator ( 3 * image.naturalWidth * image.naturalHeight ) or raise the denominator by making imageNumBytes (image size) bigger.

Evan Carroll
  • 8,863
  • 17
  • 76
  • 129
  • 2
    it is not **that** crazy: `3 * pxwidth * pxheight` is, for 8bpp RGB, the byte size for the raw image data. This ignores all headers, metadata, and file specification of course, but for a rapid file-spec-agnostic rule of thumb. it is sane. In addition, I haven't traced the code, but it assumes a canvas of 600x600 (see my comment to the question), so their method captures massive downsampling aka "effective resolution". The real problem is their failure to mention that 600px square image is optimal. – Yorik Oct 14 '21 at 16:05
  • @Yorik Good observation. That makes sense. I don't think you understand their application. The whole purpose of it is to crop a regular photo to their desired dimension with proper sizing (guidance whether or not the face is within the margin of error). If you had a perfect passport photo you wouldn't need the application to begin with. Think Mom wants a passport photo and you have have only a cell phone and the photo needs to be 2in x 2inc, with the face 1in-1.3in wide. – Evan Carroll Oct 14 '21 at 16:17
  • So reducing and printing a 7000px square image as 2inch square @ 300ppi tends to blur the contents. I think the point of the uploader is to help identify potential passport rejection problems. So objecting to an overly reduced image is possibly part of the rationale. If it were me, and I knew the desired spec(!), I would reduce the size before uploading to check for sharpness. But I have done a lot of book design even going back to the 80s so I know what to look for. The site doesn't assume lots of knowledge, but the error would be improved by actionable information for graphics design novices – Yorik Oct 14 '21 at 16:20
  • I will add that it isn't simply a wording problem: I know lots of "normal" people whose eyes glaze over even trying to relate the most basic information about size and ppi etc. – Yorik Oct 14 '21 at 16:23
  • I created [a google sheet](https://docs.google.com/spreadsheets/d/1H6C6F1E5WcT57OdhFyyT1fR5-oPRY-n-l-kAY06oMQg/edit?usp=sharing) for this. it could be useful to find out how much should you resize the image to bypass the validator. – Ali Ghanavatian Oct 29 '21 at 08:56
  • @AliGhanavatian I think the `MAX_COMPRESSION_RATIO = Infinity` trick is much easier. ;) – Evan Carroll Nov 06 '21 at 18:49
  • @EvanCarroll surely.. that disables the check altogether. I just thought there was a reason that forced the developer to write that code, and it probably would have an effect on the system or probably filter the application out. :) – Ali Ghanavatian Nov 08 '21 at 07:49
  • @AliGhanavatian Nope, you don't even have to use their tool to do this. In fact, in March [when they deprecated the Flash tool I basically just did it in Gimp (this tool wasn't out)](https://superuser.com/q/1635868/11116). Worked fine. I'm not sure why that code is there, but there is no government regulation anywhere that talks about compression ratios and how they're calculated. Government probably said "can we make sure these _very bad_ photos aren't accepted." And this is the best a stupid developer could do in the time allotted. – Evan Carroll Nov 08 '21 at 07:56
-1

Evan Carroll I am so sorry that these people are such eggheads desparate to prove how smart they are. And actually do nothing to actually answer your question, pathetic.

I got the same message. Here is what I did to fix it:

  1. Open MS Paint
  2. Click resize
  3. Click Pixels
  4. increase the pixel count. I went from 600 to 800 then try uploading again and it worked perfectly for me. Good Luck!
  • 2
    This does not provide an answer to the question. It was about doing it in an application. Once you have sufficient [reputation](https://superuser.com/help/whats-reputation) you will be able to [comment on any post](https://superuser.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/1196320) – Rohit Gupta Jun 22 '23 at 06:45