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!

share

1 Answer

up vote 67 down vote accepted

ANNOUNCEMENT: The uploader is currently broken due to an SE API change. I'm trying to figure out a fix, stay tuned. It may take a few days. If you know Java, and understand how HTTP requests work, please contact me---some help would be most appreciated.


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.

INSTALLATION:

Automatically (recommended)

Thanks to Rolf Mertig, the palette can be installed or updated by simply evaluating the following:

Import["https://raw.github.com/szhorvat/SEUploader/master/SEUploaderInstaller.m"]

Manual way

  1. Download the palette notebook
    (right click this link and choose Save As... if the CDF player starts up)

  2. Drop it in the $UserBaseDirectory/SystemFiles/FrontEnd/Palettes directory. Evaluating this piece of code will open this directory for you:

    SystemOpen@FileNameJoin[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "Palettes"}]
    
  3. Restart the Front End, and open the palette through the Palettes menu.

Note that the complete functionality is available only if the palette is installed to the Palettes menu. If the palette is correctly installed, it will be able to update itself with the push of a button.

If you need to reinstall it for some reason (broken updating), please remove all previous versions. Only one version of the palette can exist at a time (if there are several, they will conflict).

I strongly recommend that you keep the name SE Uploader.nb and do not rename the file.

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

share
It is possible to simplify installation: Import@("http:"<>"//dl.dropbox.com/u/66256747/seuploaderinst.m") will install in Mathematica 8 or 9 (and checks for lower versions). One could also set an option in $FrontEnd during installation and then the palette would not have to be tweaked w.r.t. FrontEndVersion. This happens if you do Import@("http:"<>"//dl.dropbox.com/u/66256747/installseuploader.m") – Rolf Mertig Dec 19 '12 at 20:22
@Rolf Thanks for the suggestion, maybe that's a better solution! – Szabolcs Dec 20 '12 at 17:55
@Szabolcs I just changed Import@("http:"<>"//dl.dropbox.com/u/66256747/seuploaderinst.m") slightly such that it can be used to update the palette. I deleted the other .m files in the dropbox folder. – Rolf Mertig Jan 9 at 20:20
1  
@Rolf Thanks for the reminder, I forgot about this during the Chirstmas break! – Szabolcs Jan 9 at 21:06
@Rolf Thanks again for this and sorry for the late reply. I included your simplified method in the post. It still relies on Installer.m being available on your server. I hope this is okay, if not, I'll put a copy in my Dropbox. – Szabolcs Jan 28 at 22:27
Thanks. If I find time I'll put Installer and all dependent stuff on github – Rolf Mertig Jan 29 at 1:41
Excellent! The only question remains on how to make sure the automatic installation link is not compromised. I know this sounds paranoid, but it is a potential security issue... – Yves Klett Jan 29 at 14:10
And the other question - can/should this palette functionality merged with @rm -rf´s SENotebook package? – Yves Klett Jan 29 at 14:13
@YvesKlett At least, not yet. Szabolcs has a very well polished palette with a nice and intuitive (and informative) UI. Mine is still very rough and unpolished (which is why I only released it in chat to people who know mma well enough to not panic when something breaks). If I finish that and there's good adoption, I'll add some more additional features from Sz's palette (such as history, chat upload, auto update), but that's going to be a while :) – rm -rf Jan 29 at 14:45
@Yves Do you mean that someone could edit this post and change the install link to a malicious one? I haven't thought of that. Fortunately there's a reputation limit before someone can edit a post without review so it shouldn't be a problem. Regarding modifying the installer itself and including malicious code, that is the same as modifying the palette and putting the malicious code there, so I guess it's the same. But it's good you pointed out this to me, maybe I should find a somewhat more secure hosting than Dropbox. – Szabolcs Jan 29 at 15:34
Yes, I thought in that direction - and of course, any palette or package would be just as suitable for causing mayhem, but the direct loading of the package is just so convenient... my thoughts were "o glory, how comfortable" with just a slightly guilty addition of "huh, in a crazy world I should check the code first". Perhaps I need a shrink. – Yves Klett Jan 29 at 16:35
@Yves You're not paranoid, it's a valid concertn. How about this: instead of putting an opaque Import in this post as installer code, put some transparent code (FetchURL) that also checks the hash of the palette? (Though I'd hate to lost he convenience of Rolf's simple InstallPalette) – Szabolcs Jan 29 at 17:30
Yes, perhaps some kind of hash check would be a good addition. In a larger context, are there any mechanisms to install packages et. al. from trusted sources? – Yves Klett Jan 30 at 8:59
1  
@hhh I'm not sure what you mean by this. What is "Apple-OSX-style screenshots uploading" and which error reports are you talking about? What the palette does is it lets you select, rasterize and upload any part of a notebook, not just images. Like this: i.stack.imgur.com/ji7F2.png – Szabolcs Mar 21 at 1:18
1  
I see that folks are still uploading images. Given that SE Uploader still seems to be broken, how upload now? – murray Apr 28 at 15:37
show 11 more comments

You must log in to answer this question.

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