Help:JPEG

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

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

[edit]

The text below is copied from Commons:File types #JPEG: JPEG (also JPG) is appropriate for photographs, especially when the photographs are already JPEGs. 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. However, if the original file is in JPEG, it generally 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 (any edits, however, should probably be saved as PNG as well as JPEG). An exception is high resolution JPEGs that have no visible compression artifacts. Conversion to PNG will avoid the thumbnails having additional compression artifacts.

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. Use {{JPEG version of PNG}} on the JPEG versions of a PNG flagged as {{PNG with JPEG version}}.

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 also Help:Scanning[Note 1]

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.[Note 2]

Editing JPEGs

[edit]

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 (example). (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. On Commons, the section “File history” of the file page usually contains links to earlier versions.

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 (8×8, 16×8, 8×16, or 16×16) 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

[edit]

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 1,000 megapixels is in effect.[Note 3] Large JPEGs are usually problematic only if they are saved in progressive mode; use baseline mode instead (see Progressive JPEGs). End of copy

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

Progressive JPEGs

[edit]
Shortcut

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).

If you're unsure about your JPG being interlaced:

  • 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

[edit]

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

Rotated JPEGs

[edit]

See Commons:Rotation

Metadata

[edit]

Exif

[edit]

See Commons:Exif.

Comment

[edit]

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

Color profile

[edit]

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

[edit]

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

[edit]
  1. For JPEG also see A few scanning tips, scantips.com, 2010 by Wayne Fulton.
  2. See Commons:Village pump #BadJPEG, 15 June 2011.
  3. Megapixel (number of frames × width × height), downsampling formula (for the WikiMedia limit, keep SAR): floor (√Megapixel limit × width ÷ height) ≥ widthnew, for animation (furthermore and with loss SAR): floor (Megapixel limit ÷ frames ÷ height) ≥ widthnew

See Also

[edit]
[edit]