1
$\begingroup$

Below is an image as captured by a screen-capture app; it faithfully represents what I see in the Mathematica notebook's window (right after re-starting Mathematica, and opening the notebook; magnification = 100%):

enter image description here

Now, this is the same image as captured by the SE uploader (latest version):

Mathematica graphics

To capture the last image, I

  1. select the cell containing the image;
  2. click on the Image button on the SE Uploader's palette;
  3. click on the Upload for site button in the ensuing dialog.

How can the discrepancy be explained?


FWIW, the code that generated the widget shown in the image is this:

Manipulate[
 Graphics[{}
  , Background -> LightGray
  , AspectRatio -> 1.
  , ImageSize -> Small
  , Frame -> True
  , FrameTicks -> {{None, All}, {All, None}}
  , FrameTicksStyle -> Directive[FontSize -> fontSize]
  , ImagePadding -> {{0, Scaled[scaledRightPadding]}, {Scaled[scaledBottomPadding], 0}}
  ]
 , {{scaledRightPadding, 0.0515}, 0, 0.2, LabeledSlider}
 , {{scaledBottomPadding, 0}, 0, 0.2, LabeledSlider}
 , {{fontSize, 10}, 1, 60, 1, LabeledSlider}
 ]

The version of Mathematica I'm using is

10.4.0 for Linux x86 (64-bit) (February 26, 2016)

$\endgroup$
3
  • 1
    $\begingroup$ Last time I looked at it, Mma for Linux did not support pixel-accurate capture. On Windows/OSX there is another capture method which is more faithful to the original. $\endgroup$
    – Szabolcs
    Commented Feb 9, 2017 at 17:42
  • $\begingroup$ If you have the time, you could try to figure out if there are better ways to capture the image in recent versions of Mathematica. Useful references: stackoverflow.com/q/8353838/695132 mathematica.stackexchange.com/a/1411/12 I really don't have time to tinker with this. If you do, and you find a better solution, everyone will benefit. $\endgroup$
    – Szabolcs
    Commented Feb 9, 2017 at 17:48
  • $\begingroup$ @Szabolcs: Thanks for the info. After tinkering some more, I found that the width (in pixels) of the right padding changes as one resizes the notebook's window's width. This does not happen if one uses a fixed, rather than a Scaled[] value in the ImagePadding setting. Therefore, the problem may be a bug in the way Mathematica handles Scaled[] values for ImagePadding. (I call this a bug, because there's no reason for Scaled to respond to the width of the notebook's window.) $\endgroup$
    – kjo
    Commented Feb 9, 2017 at 18:01

1 Answer 1

1
$\begingroup$

The uploader can use two methods to capture an image. They are (partially) described here:

The first method simply copies the expression into a new invisible notebook, then rasterizes the whole notebook. This method has a few problems:

  • Dynamic stuff like Manipulate may get re-evaluated
  • Formatting that depends on the notebook width will change. The invisible notebook is created with a fixed width that is hard-coded into the palette code (I forgot what it was).

You use Scaled image padding, i.e. you explicitly made the padding dependent on the window width. Try resizing your window and see how the figure changes. This is why it looks different when the palette copies it to a new (invisible) notebook of a different width.

The second method uses an entry from the Edit -> Copy As... menu that produces a bitmap. This tends to produce a result that is faithful to the original down to the pixel level (except on "retina" screens).

The available Copy As entries are different for each OS. Last time I checked, Linux had no way to copy graphics as bitmap, so this method is not available on Linux.


Perhaps it is time to review what other methods can be used to capture bitmaps, and see if anything was introduced in recent Mathematica versions that can also be used on Linux. I do not have time to do this, but you are welcome (and encouraged) to try.

Things I would try:

  • Create a selection in the notebook (NotebookSelection) and use Rasterize with it. Last time I looked, this did not work with selections that were smaller than a cell.

  • Spelunk a bit to try to find new Copy As formats on Linux

  • Spelunk a bit to see if anything can be done with ExportPacket


Finally, I wanted to say that I rarely use the upload palette these days because now there are more convenient methods available. On OS X I can copy a manually selected rectangle from the screen using Command-Shift-Ctrl-4. If I use the Chrome browser, I can directly paste (Command-V) this into the image upload box, without the need to save the image to disk and browse for it. I only use the palette for chat and comments, where the image upload box is not available.

Try to see if similar functionality is available on Windows or Linux (i.e. copy rectangle and paste into Chrome), and if it works, use that instead.


I always suspected (but I am not sure) that the problem on Linux is that in the past it did not have a standardized clipboard like Windows and OS X do, and Mathematica could not reliable put image data (as opposed to simple text) onto the clipboard. However, today I can copy an image in Firefox and paste it into a rich text editor, or even into Mathematica, without problems. So perhaps it is time to petition Wolfram Research to add support for copying images on Linux.

$\endgroup$
4
  • $\begingroup$ I am now confused: where do you get that Scaled is relative to the window's width? I thought it was relative to PlotRange. $\endgroup$
    – kjo
    Commented Feb 9, 2017 at 18:04
  • $\begingroup$ In fact, I've seen this dependence of Scaled parameters on window size only when Scaled is applied to an ImagePadding setting. For every other image that I've checked where Scaled is used, the appearance on the screen remains constant as the window's size changes. $\endgroup$
    – kjo
    Commented Feb 9, 2017 at 18:10
  • 1
    $\begingroup$ @kjo I tried it and that's how it works. Sorry, I don't know why. How Scaled works depends on the context where it is used, and sometimes it doesn't make much sense to me ... $\endgroup$
    – Szabolcs
    Commented Feb 9, 2017 at 18:10
  • 1
    $\begingroup$ @kjo Scaled also works this way in ImageSize, but there it makes more sense. $\endgroup$
    – Szabolcs
    Commented Feb 9, 2017 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.