Server-side graphics in ASP.NET Core

I recently upgraded an ASP.NET MVC application from ASP.NET to the ASP.NET kernel.

In my controller action, I had a piece of code that relied on System.Drawing to create a profile image

using (FileStream stream = new FileStream(HttpContext.Server.MapPath($"~/Content/UserFiles/{AuthenticatedUser.Id.ToString()}.jpg"), FileMode.OpenOrCreate)) { Image image = Image.FromStream(model.DisplayPicture.InputStream); image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); } 

Image data is sent to the server as a Base64 encoded image.

 data:image/png;base64,.... 

Since there is no System.Drawing in .NET Core, are there any other libraries that can do this?

+3
source share
2 answers

As Stanislav noted, the current solution is to use ASP.NET Core on the full .NET platform. System.Drawing relies on GDI + calls, so it is connected with Windows.

Imazen's vNext Image Resizer version will solve this problem based on the new imageflow project. System.Drawing should not be used in server environments such as ASP.NET (indicated by https://msdn.microsoft.com/en-us/library/system.drawing(v=vs.110).aspx ). Some information on this topic is provided at https://github.com/imazen/Graphics-vNext .

I suggest using the current version 4.0.5 of ImagerResizing and updating in a few months (the first stable version of vNext is announced next year).

+1
source

You do not need System.Drawing if all you are trying to do is convert base64 to image files. I do this in my cloudscribe.SimpleContent project. Users add images and content in the wysiwyg editor, and when it sends messages back to the server, I convert them to files and resolve the URLs for the files to update the content so that it refers to the new file.

Here you can see my working code: https://github.com/joeaudette/cloudscribe.SimpleContent/blob/master/src/cloudscribe.SimpleContent.Web/Services/FileSystemMediaProcessor.cs

We need to use System.Drawing or some other tool to resize and optimize images. There is an ImageSharp project here that is working on this, although I'm not sure how many features are currently ready.

+1
source

All Articles