Skip to content

Save Plot as Image: let the user choose a compression method for TIFF output #19114

Closed

Description

@kevinushey

Summary

Plots saved as TIFF from the Plots pane are always uncompressed. R's grDevices::tiff() and ragg::agg_tiff() both default to compression = "none", and RStudio doesn't pass a compression argument when it creates the export device (savePlotAsBitmapFile in src/cpp/r/session/graphics/RGraphicsPlotManager.cpp). JPEGs are always saved at quality = 100.

With the fixed plot size and export resolution options from #18895, this gets noticeable: a 7 x 5 in plot saved at 300 DPI is a 9 MB TIFF, and 36 MB at 600 DPI, while the same image is under 1 MB with LZW compression. Journals commonly ask for LZW-compressed TIFFs, which is what @Breeze-Hu asked for in #18895 (comment).

Proposal

Add format-specific options to the Save Plot as Image dialog, remembered in export_plot_options alongside the format and resolution:

  • TIFF compression: None, LZW, ZIP (possibly the +p predictor variants), defaulting to LZW.
  • JPEG quality: a choice such as 100 / 95 / 90 / 75 (R's own default is 75). Keeping 100 as the default leaves existing output unchanged.

Pass them through save_plot_as to the device:

  • grDevices::tiff(..., compression = "lzw") and grDevices::jpeg(..., quality = 95) for the cairo, Xlib and Windows device types. R maps the compression name to the libtiff code itself, so this needs no new native dependency.
  • ragg::agg_tiff(..., compression = "lzw") and ragg::agg_jpeg(..., quality = 95) when the ragg backend is selected; they accept the same values.
  • The Quartz device (the default on macOS) ignores both: tiff() warns that compression is not supported, and jpeg() silently drops quality. Both write the file through ImageIO with no properties (QuartzBitmap_Output in grDevices' qdBitmap.c). RStudio already rewrites Quartz bitmaps through ImageIO to record their resolution (ensureImageResolution in RGraphicsImageResolution.cpp), so that pass can set kCGImagePropertyTIFFCompression in the TIFF dictionary (5 = LZW, 8 = ZIP) as well. For JPEG, re-encoding Quartz's already lossy output would degrade it, so on Quartz the plot should be drawn as a PNG and converted to JPEG through ImageIO with kCGImageDestinationLossyCompressionQuality, in the same pass that records the DPI. What ImageIO writes for TIFF when no compression is given still needs to be checked on a Mac.

Measurements

The same base-graphics scatter plot, 7 x 5 in, saved with R-devel on Windows. The windows device type is RStudio's default there; cairo is what Linux (and the "Cairo" backend option) uses.

Output 300 DPI 600 DPI
TIFF, none (windows) 9.01 MB 36.05 MB
TIFF, LZW (windows) 0.10 MB 0.28 MB
TIFF, ZIP (windows) 0.08 MB 0.22 MB
TIFF, none (cairo) 9.01 MB 36.05 MB
TIFF, LZW (cairo) 0.29 MB 0.73 MB
TIFF, ZIP (cairo) 0.29 MB 0.70 MB
PNG (windows, 8-bit palette) 0.06 MB 0.16 MB
PNG (cairo, 24-bit RGB) 0.36 MB 0.86 MB
JPEG, quality 100 (cairo) 0.51 MB 1.35 MB
JPEG, quality 95 (cairo) 0.31 MB 0.82 MB
JPEG, quality 90 (cairo) 0.23 MB 0.64 MB
BMP 3.01 MB 12.02 MB

Notes

  • No PNG option is proposed. PNG output is already deflate-compressed by every device, and a higher zlib level only buys a few percent. The difference between the Windows and cairo PNGs above is that R's Windows device writes an 8-bit palette PNG when the plot has at most 256 colours, while cairo, ragg and Quartz write truecolor; palette quantization is lossy for anti-aliased plots, so it isn't something to add either.
  • BMP is uncompressed by definition.
  • The Viewer pane's export is a screenshot taken by Electron (PNG or JPEG at quality 100, in gwt-callback.ts) and can't produce TIFF, so it's not covered here; a JPEG quality option there would be a separate change.

Activity

  1. self-assigned this
    on Oct 15, 2026
  2. kevinushey commented on Oct 27, 2026

    @kevinushey
    CollaboratorAuthor

    Implemented in #19115 (RStudio 2026.11).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions