Upload images to Imgur from Mathematica

后端 未结 3 968
有刺的猬
有刺的猬 2020-12-13 03:30

Here\'s a challenge to all mathematica tag followers. Let\'s make it a lot more convenient to insert images into SO post from Mathematica by creating an imgur

3条回答
  •  天命终不由人
    2020-12-13 04:13

    A little bird just informed me of a Mathematica solution to this question (the underlying implementation still uses JLink, but this answer hides all the java related code):

    imgur[expr_] := Module[
     {url, key, image, data, xml, imgurUrl},
     url = "http://api.imgur.com/2/upload";
     key = "c07bc3fb59ef878d5e23a0c4972fbb29";
     image = Fold[ExportString, expr, {"PNG", "Base64"}];
     xml = Import[url, 
      "XML", "RequestMethod" -> "POST", 
      "RequestParameters" -> {"key" -> key, "image" -> image}];
     imgurUrl = Cases[xml, XMLElement["original", {}, {string_}] :> string, 
      Infinity][[1]];
     "![Mathematica graphic](" <> imgurUrl <> ")"
    ]
    

    This is V8 only and the XML import options "RequestMethod" and "RequestParameters" are undocumented and experimental (and therefore subject to change).

提交回复
热议问题