Jump to content

C# plugin image processing


pünktchen

Recommended Posts

pünktchen

@roaku maybe you can help me with this and know if it's possible at all with Emby's own api:
I want to take an existing local image (it's not an image of a library item), scale it and draw it on a transparent background with an other size. The background has to be created first. 
Finally save the resulting image somewhere of course.

Edited by pünktchen
Link to comment
Share on other sites

roaku

Well, the back end of Iconic at its core is an implementation of Emby's IImageEnhancer interface. This means that functionally, Emby executes my implementation's methods when an individual image is requested through the image api.

So, my code never manipulates a source image or acts on its own in a task or from direct user interaction. It's just one of n number of enhancers that Emby core uses to tweak a derivative image on it way to the image cache.

I'm really not sure what kind of file access Emby allows the plugins when it comes to independently opening image files or where new files can be saved. I just haven't had a need to try that.

 

For the image manipulation part, Emby uses SkiaSharp or ImageMagickSharp and their respective native libraries depending on the platform, so you have to have parallel implementations of your image manipulation code and some logic to detect which library is available based on IImageProcessor.ImageEncoder.Name.

For SkiaSharp, you import SkiaSharp, then read a ton of documentation and guides to figure out how to do what you need to do.

From what you described, you'll need at least SKBitmap.Decode(), SKBitmap.Resize(), SKImageInfo and probably SKCanvas() for overlaying your source image onto the background image.

https://docs.microsoft.com/en-us/dotnet/api/skiasharp.skbitmap.decode?view=skiasharp-2.80.2

 

For ImageMagickSharp, you import ImageMagickSharp and will need to get familiar with MagickWand.ResizeImage, DrawingWand, and PixelWand.

https://github.com/MediaBrowser/ImageMagickSharp

 

Hope that helps.

Link to comment
Share on other sites

It sounds like you actually want to implement is a metadata (image) provider as opposed to an image enhancer.

Link to comment
Share on other sites

pünktchen
1 hour ago, roaku said:

For SkiaSharp, you import SkiaSharp

I was doing that in the past but wanted to get rid of the reference because Luke told me once it will make problems on .Mono installations (do they even exist nowadays?). I will now try it with ffmpeg.

Link to comment
Share on other sites

roaku
1 hour ago, pünktchen said:

I was doing that in the past but wanted to get rid of the reference because Luke told me once it will make problems on .Mono installations (do they even exist nowadays?). I will now try it with ffmpeg.

Yes, that's why you have to provide a separate ImageMagickSharp implementation for those platforms.

FreeBSD is the only one I know specifically that uses ImageMagick, so I use a FreeBSD vm as my test server for that implementation.

But yes, if ffmpeg can do what you want and isn't too much trouble, then sure.

Edited by roaku
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...