Can I change the compression ratio of a JPEG image on travel.state.gov?
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, t) {
return 3 * image.naturalWidth * image.naturalHeight / imageNumBytes
}
Our options
-
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 makingimageNumBytes
(image size) bigger. -
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.