119

Graphics are tightly integrated into the Mathematica interface. The Front End is programmable, and Mathematica has functions to interface with the web, so the question naturally comes up:

Could we make it possible to upload images to StackExchange directly from Mathematica, using a palette button, and without the need to first save them to disk?

See the answer below for an implementation!

0

3 Answers 3

102

Update 30th March 2015:

As of today, the old repository will no longer be maintained. All the former functionality can now be found in the new SE Tools package. The online repository contains a very detailed description how it works and how it can be installed.


Original Post

This is my implementation (with contributions from @halirutan and help from a number of people) of an image uploader palette, which I would like to share with the community to make it more convenient to use this site.

USAGE:

  • When correctly installed, you should see a palette like this:

    enter image description here

  • To upload, just select a graphics (or any other part of the notebook), and press the "Upload to SE" button to get a preview before uploading:

    enter image description here

    On Windows there are two buttons: "Upload to SE" and "Upload to SE (pp)". The "pp" (pixel perfect) one will rasterize the selected notebook element exactly the same way you see it in the notebook. Unfortunately I haven't (yet) been able to make this work on platforms other than Windows. The "Upload to SE" button will reformat everything to a width of 650 pixels and will discard any style/magnification information.

  • You can also see the history using the "History..." button. This will show you your recent uploads and you can click on an existing image to copy its URL or clear the history.

    enter image description here

  • To update, simply use the Update... button. If there is an update available, this button will turn pink. The palette automatically checks for updates every few days (if it is open).

  • You can also watch a screencast showing how to use the palette.

BUG REPORTS, SUGGESTIONS, DEVELOPMENT:

Ideas, suggestion, code improvements, problem reports are most welcome! Pease use the GitHub bug tracker for bug reports or feature requests. Just comment on this post for anything else.

The source code is available through GitHub.

Feel free to fix problems yourself and send pull requests. This can even be done through the GitHub web interface.

KNOWN ISSUES

There are a few problems that have happened to people, but I am not able to reproduce them. If you can come up with a way to reproduce any of these, please contact me!

  • Sometimes none of the palette buttons do anything. Pressing Update or History will not bring up a new window either.

    If this happens to you, close the palette and re-open it from the Palettes menu. If that doesn't fix the problem, then open the palette, evaluate SEUploader`checkOnlineVersion[], then close and re-open the palette.

  • Sometimes no palette buttons show at all, just the Mathematica.SE logo on the left. If you can reproduce this, please contact me.

  • The thumbnails of old uploads (upload history) may get corrupted for reasons unknown to me. The symptom is an error or hang when you press the History button or an error every time you try to upload. To fix this, first try clearing the history in the History... dialog. If the front end hangs when you try to open the History window, clear the history as follows:

    1. Close the palette and restart the Front End

    2. Identify the file name of the palette. It's found here: SystemOpen@FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "Palettes"}]. Let's call it SE Uploader.nb.

    3. Evaluate CurrentValue[$FrontEnd, {"PalettesMenuSettings", "SE Uploader.nb", TaggingRules}] = {} and restart the front end. Make sure you use the correct file name for your system in place of SE Uploader.nb. Only use the file name, not the full path. Alternatively this front end option can be cleared using Format -> Option Inspector after selecting Global Preferences in the top left dropdown.

    4. Restart the Front End again, open the palette and check that the History... button brings up an empty window. If the problem was due to corrupted history entries, it should be fixed now.

  • When running in HiDPI mode on OS X, there may be a thin line on the right edge of uploaded images.

UNINSTALLING

If you used the suggested method to install the palette, the following will remove it completely and clear all settings. This is useful if you are having problems with the palette and want to try reinstalling it.

Close the palette, then evaluate the following:

DeleteFile[FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "Palettes", "SE Uploader.nb"}]]

CurrentValue[$FrontEnd, {"PalettesMenuSettings", "SE Uploader.nb"}] = {}

CurrentValue[$FrontEnd, TaggingRules] = DeleteCases[
  CurrentValue[$FrontEnd, TaggingRules], 
  "SEUploaderLastUpdateCheck" | "SEUploaderVersion" -> _]

Now restart the front end (quit Mathematica completely).

2
  • Works marvellously, thanks for all the hard work! Commented Oct 1, 2013 at 18:50
  • 1
    I have a problem win Windows 8.1 64 and Mathematica 9 or 10. I receive the message "PrependTo::normal: Nonatomic expression expected at position 1 in PrependTo[CurrentValue[SEUploaderPrivatepnb, {TaggingRules, ImageUploadHistory }],..." after the image has been uploaded...
    – unlikely
    Commented Jul 18, 2014 at 11:44
4

Here is an alternative process to add Mathematica graphics to MMA.SSE directly taht requires no plug in. Select a graphic within Mathematica, then in the menu select Edit >> CopyAs >> Bitmap, then paste directly in the SE editor page, e.g. using CTRL+V on a Windows system, or the equivalent.

Perhaps this is well known to other site users, but I was unaware of this for years, until @kglr mentioned it in passing in a comment on the main site. This has greatly simplified my answering workflow!

1
  • On a Mac you can select the graphics or its cell, <kbd>cmd</kbd>-<kbd>C</kbd> and then <kbd>cmd</kbd>-<kbd>V</kbd> in the SE edit window. It gives a full-width image, as does copy-as-bitmap, which I find too large. Copying the whole cell includes whitespace to right, probably to fill out the notebook window width. You still get a full width image, but the graphics look smaller.
    – Michael E2
    Commented May 24, 2022 at 14:26
1

My version of Mathematica Home 12.0.0 allows this even more comfortable and easy. I am sure this is the very same for newer versions of Mathematica and for wolfram cloud graphics.

Produces a graphics output in the notebook then hoover the graphics output and click the right mouse button or command + mouse on Mac. A dropdown menu of the graphics output opens. Click left on Copy Graphic.

Change back to the input field of stackexchange.com and click Crtl+V a dialog for graphics input appears in the stackexchange.com input field to confirm if you like to add the graphic to the answer.

The graphics appear and is already uploaded to an attached content server of StackExchange. There is then a link added in the footer of your answer.

Plot[{x, -x}, {x, -1, 1}]

my picture

You are enabled to add a hoover message to the graphic inside your answer text.

I judge that the operation is about the same than just editing this is a notebook.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .