# Help:JPEG

JPEG is a commonly used lossy compression image format. The purpose of this help page is to provide detailed information for Commons uploaders or users on the specific JPEG (or JPG or jpg or jpeg) image file format. It concerns both the pictures uploaded in this format and the thumbnails generated in this format by the Mediawiki software, sometimes after converting a different original format. For general information see the JPEG article on Wikipedia.

## JPEG versus other formats

The text below is copied from Commons:File types#JPEG:

JPEG is appropriate for “photographs”; JPEG uses "lossy compression", sacrificing precision for smaller file size.

If you have a choice of file formats in which to save a graphic, scan, or other such thing, save it as PNG (or save it as another lossless format, such as TIFF, and convert to PNG), and upload it as such. Even though PNGs over 2,500 megapixels cannot, at this time, be displayed on Wikipedia, the file will be able to be downloaded, and you can always convert the PNG to JPEG and upload that as an alternative. However, if the original file is in JPEG, it makes no sense to convert it to PNG: converting a lossy compression into a "lossless" format doesn't buy you anything since the "loss" already occurred in the original, and doing so will only increase the file size.

Note that currently JPEG thumbnails receive extra sharpening, while PNG thumbnails don't. Hence, uploading in both formats may be a good idea if the PNG thumbnails look a bit blurry.

PNG is a lossless full-color format. JPEG is always a lossy format even at the highest quality settings. Lossless formats do not degrade after being saved repeatedly, but lossy ones do; hence, having a lossless version of the file allows the file to be tweaked for various purposes — cropping, levels adjustment, and so on — without a loss in quality.

See [1] [2] and Commons about Scanning

End of copy.

JPEG files with picture data which by its nature is not suitable to be encoded in the JPEG file format (such as graphs, diagrams, computer-generated maps, (flat) flag designs, and other "cartoony" pictures with large areas of flat color, thin lines, and sharp brightness transitions) are tagged with {{BadJPEG}}, which recommends that such pictures should be represented by PNG or SVG image files instead. (See Commons:Village pump#{{BadJPEG}}, 15 June 2011.)

## Editing JPEGs

Opening a JPEG file, editing it and saving it again applies additional lossy compression to an image that may already have some visible distortions caused by previous compression. Doing so repeatedly can have a severe impact on the image quality. (Repeatedly saving an image during a single editing session without closing the file in between does not have the same compounding effect.)

When modifying existing images, it is therefore best to start with a losslessly compressed original, if one exists. If it does not, one should prefer versions that have as few previous edits as possible.

When editing a file that has already been subjected to JPEG compression, saving the edited file with the same compression parameters as used in the original file, and keeping the boundaries between pixel blocks (8x8, 16x8, 8x16, or 16x16) in the same places, can minimize the addition of new JPEG artefacts. Alternatively, if this is not possible, increasing the quality setting when saving will introduce fewer new distortions at the expense of an increased file size. (However, increasing the IJG libjpeg quality setting all the way to 100 increases the image filesize greatly over a quality setting of 95, with almost no improvement in real image quality.) Or the file can be saved in a lossless format to avoid introducing any new distortions.

Some operations can be performed losslessly on JPEGs using special tools instead of general image editing software. This includes cropping and rotating. Lossless cropping is limited to a coarse grid, meaning that cropping to remove an exact number of pixels from the edge of the image may not be possible. Rotating is limited to multiples of 90 degrees. When rotating or cropping JPEG images, use tools that operate losslessly whenever possible. Cropbot can be used to losslessly crop JPEGs, and the RotateLink gadget can be used to request rotation, which is done losslessly.

## Large JPEGs

The text below is copied from Commons:File types#Size and scaling:

Note that scaling of images may fail if the image is very large and rendering takes too much time or memory (in that case, either no scaled image is shown, or the full image is served to the browser, often causing it to lock up). For GIF images, a hard limit of 50 megapixels is in effect.[Note 1] Large JPEGs are usually problematic only if they are saved in progressive mode; use baseline mode instead (see below).

End of copy

Large images (not only JPEGs) can be tagged with {{LargeImage}} which provides a link to a special viewing tool.

## Progressive JPEGs

Do not use interlaced (a.k.a. progressive) JPEG compression: save your JPEG images in baseline mode. This will ensure that thumbnails are efficiently produced in all cases possible, while otherwise they'll require way more memory on the server and often fail (you'll get Error creating thumbnail: convert: Insufficient memory; technical background on bugzilla:17645).

GIMP – save jpeg
PS - save jpeg

Some software saves in progressive format by default, because it's supposedly better for the web (before downloading the whole image, one can see a degraded version of it already): be sure to disable this option, see the screenshot for an example.

Hint: Some Adobe products, i.e. Photoshop CS5, seems to have a bug: the first option always produces a progressive jpeg. Choose the second option in this case (see thumb).

If you need to convert a JPEG not created by you, open it in one such software and re-export/save it appropriately, or:

• with imagemagick just use convert in.jpg out.jpg (-interlace none is the default);
• with jpegtran (less memory required), jpegtran -copy all -perfect in.jpg > out.jpg (with -perfect it's a completely lossless conversion, but it may fail in some cases; just remove the option if this happens).

• with imagemagick, identify -verbose image.jpg: any output other than "Interlace: None" in the relevant line indicates an interlaced JPEG;
• with exiftool, exiftool -fast2 image.jpg: any output other than "Baseline DCT" in the relevant line indicates an interlaced JPEG (this command is a couple of orders of magnitude faster than the previous one; highly recommended).
• use the online tool Jeffrey's Exif Viewer and upload the image to test. In the results check the table "File" -> "Encoding Process"

## Broken JPEGs

Files tagged with {{Broken file|filetype=JPG|description=}} are inserted into Category:JPG files with errors. Sometimes it's possible to repair corrupt JPEGs using JPEGsnoop or similar JPEG recovery tools.

## Rotated JPEGs

### Exif

See Commons:Exif.

### Comment

The URL of the picture on commons is included in the "jpeg comment" metadata, in thumbnails generated after April 2010 (Bugzilla).

### Color profile

Some thumbnails generated before August 2010 may encounter incorrect color rendering (Village Pump)(Bugzilla).

This file was striped and showed the CMYK bug.

## Color model

CMYK images sometimes suffered from thumbnail artifacts or are not supported by certain browsers. Therefore please upload RGB images. Bugzilla Search, bugzilla:24854 You can use e.g. GIMP to fix such images. Just open and save ("save as ...") again with maximum jpeg quality. Explanation: As of now GIMP isn't able to save CMYK jpegs and therefore automatically reduces them to RGB. You may also use IrfanView for Windows.

## Notes

1. Megapixel (number of $\text{frames × width × height}$), downsampling formula (for the WikiMedia limit, keep SAR): $floor ( \text{√(12.5 Mpx × width ÷ height)})\text{ ≥ }width_{\text{new}}$, for animation (furthermore and with loss SAR): $floor ( \text{12.5 Mpx ÷ frames ÷ height})\text{ ≥ }width_{\text{new}}$