Comments (7)
Just had a go at supporting PNG images and it seems to be working fine. See Commit
And then the code
#r System.Drawing
using System.Drawing;
using System.Drawing.Imaging;
public static partial class Test
{
public static string GetPng()
{
using (Bitmap b = new Bitmap(50, 50))
{
using (Graphics g = Graphics.FromImage(b))
{
g.Clear(Color.Green);
}
var str = new MemoryStream();
b.Save(str,ImageFormat.Png);
return System.Convert.ToBase64String(str.ToArray());
}
}
}
can be used to output a green square in a separate cell with
Test.GetPng()
But yes, ideally, the results of the execution should be parsed for type, mime type deduced and then encoded to base64. Doesn't sound that complicated
from icsharp.
@awb99 Thats a great suggestion. Do you have the Grid encoder in an open repo so that I can take a look at it to get a better idea of what you are proposing design wise.
from icsharp.
@zabirauf Not yet. I have it already, but need to factor this part out to a dedicated project. I promise to do so!
from icsharp.
@zabirauf https://github.com/awb99/ObjectPrinter.git
I factored out some basic functionality into this github project.
I added a feature to print a list of objects of a specific type to a html table.
For individual objects, I would rather export as a format more similar to JSON
I am not sure if we should put the dataType (jpg/html/text/...) into the ObjectPrinter; or if this should be done icsharp.
from icsharp.
Html seems to be possible as well automatically but need a proper function to check for presence of tags. See commit
var html = @"<b>Bold</b>" + "<br>" + "<i>Italic</i>";
This would output
Test
Italic
from icsharp.
Re the design concerns. While it might be nice to be able to specify explicitly in user code the return type it's a bit cumbersome dependencies wise. What would need to happen is creating a separate interfaces project which will be a common dependency of icsharp and your user code. And there's no nuget support in Ipython so instead of just distributing the kernel as an .exe file an additional dev package will need to be included plus installed to GAC as ScriptCS can only reference either those or absolute paths.
What I would rather suggest is a combination of automatic detection plus some conventions. E.g. if a function returns a Dictionary< string,object > then the first component is expected to represent the mime type. Then the conversion functions to base64 can be pulled into isharpcs directly.
Although now that I think about it one other option is maybe preinjecting the interfaces into each ScriptCS istance explicitly in ISharpCS code. Not sure if that's completely straightforward though. That could also be combined with attributes e.g.
[OutputType("text/html")]
public static string WriteHtml()
{
return @"<b>Bold</b>" + "<br>" + "<i>Italic</i>";
}
from icsharp.
Here's also an example of directly returning HTML with embedded images
using System.Math;
public static partial class Test
{
public static string Html()
{
var html = @"<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' alt='Red dot'></img>";
return html;
}
}
will result in a red dot displayed.
Just put all examples in a single notebook
https://github.com/zedr0n/icsharp/blob/dev/iPythonNotebook/MimeTest.ipynb
from icsharp.
Related Issues (20)
- Not able to build the solution with VS2017 HOT 2
- Kernel crashes (WindowsError) HOT 2
- Project does not build on Visual Studio 2015 Windows HOT 2
- Compile error due to xunit.runners HOT 10
- Support for Jupyter Lab HOT 3
- insert on ubuntu18.04
- The type or namespace name 'LibLog' could not be found HOT 1
- StackOverflow in IoPubConsole in Debug mode
- vs2017 build failed HOT 7
- PermissionError: [Errno 13] Permission denied HOT 2
- 'ScriptResult' could not be found
- It is possible to upgrade to .netstandard 2.0
- Compile fails on Windows10 x86-64, help or get me a pre-compiled installable HOT 3
- Made Docker image for use in mybinder.org HOT 2
- Not able to build with VS2015 HOT 3
- Error 1043
- Unable to install on Manjaro HOT 2
- Is this project abandonded? HOT 3
- Is there a sample code of how to use nuget command ? HOT 2
- Kernel not found: None
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from icsharp.