dlemstra / Magick.NET

The .NET library for ImageMagick
Apache License 2.0
3.47k stars 415 forks source link

Linux support? #74

Closed stephanbruny closed 7 years ago

stephanbruny commented 7 years ago

Hello,

is it (already) possible to execute Magick.NET within a Linux-environment? My humble tries, to run on Ubuntu 16.04, ended in various Exceptions from the Native-DLL.

If not, a Linux-build should be possible, as far as I can say from the C-Sources?

dlemstra commented 7 years ago

Linux support is not implemented but it should be possible. I (or someone else) need to create a script that compiles the native code of Magick.NET and link this with the libraries of ImageMagick. More info can be found in issue #16. I just got a great reply from @markbeaton who says he will take a look at making this possible. I hope he will succeed.

stephanbruny commented 7 years ago

That's good news. I'll give it a try too, using VS2017, and the cross-compile feature for linux binaries.

If Magick.NET.Native-Library is successfully built for Linux, wouldn't it be sufficient to simply deploy the .so-file with the NuGet-Package and modify the dllMap?

dlemstra commented 7 years ago

It might be sufficient to deploy the .so files and change the P/Invoke but I am not sure about the UTF8 handling. But I have a bunch of unit tests for this if we can get the build working.

stephanbruny commented 7 years ago

I managed to (at least) compile via VS2017 on a Linux remote. Linking will be a little fun part though.

dlemstra commented 7 years ago

That's great news 🍾 . Yeah we also need something to compile the ImageMagick code and I would prefer to use the repos that are cloned in this repo: https://github.com/ImageMagick/ImageMagick-Windows ( CloneRepositories.sh). This will make sure that the version of the dependencies are the same.

stephanbruny commented 7 years ago

Allright, I have a compiled and linked version of the Native-DLL, and it seems to run on my Linux host. At least I get Version, Features, Formats, etc. from MagickNET-Namespace.

Now, trying to do something results in a "Could not load assembly 'PresentationCore'. Of course, Mono does not ship any WPF features. So what is PresentationCore used for, and how could we possible substitue it?

dlemstra commented 7 years ago

You should only need PresentationCore when you target net40 (https://github.com/dlemstra/Magick.NET/blob/175fe3b31a1fb218433e605f90751f1df1300017/Source/Magick.NET/Magick.NET.csproj#L25). Are you building netstandard13?

How did you link ImageMagick?

stephanbruny commented 7 years ago

Here is what I have done so far:

I created a new Linux-C++-Project, copying all sources from Native. Then I replaced some defines and functions with Linux-specific ones; Compiled the latest ImageMagick from source on my Linux host, and link statically against the build (currently Q8, x64) and libjpeg.

To use it, I didn't even recompile Magick.NET. All I have done was to replace the Native-DLL with the Linux-build and let Mono figure out the rest. ...not a very sophisticated approach

stephanbruny commented 7 years ago

OK, so I recompiled Magick.NET targetting net20, replaced Native again with my linux build, and it seems to run

stephanbruny commented 7 years ago

I made a repo, containing my current changes: https://github.com/stephanbruny/Magick.NET.Native-Linux

dlemstra commented 7 years ago

Thanks for sharing this 👍. Would you mind having a chat on Skype later this week? Got a couple more questions.

ktngoykalolo commented 7 years ago

You could try with the original C sources from ImageMagick. There is a version of the code that is native on Linux. I was also thinking of building a x-platform version from the original C sources. Keep us posted. ??

Provenance : Courrierhttps://go.microsoft.com/fwlink/?LinkId=550986 pour Windows 10

De : Stephan Brunymailto:notifications@github.com Envoyé le :lundi 17 juillet 2017 19:01 À : dlemstra/Magick.NETmailto:Magick.NET@noreply.github.com Cc : Subscribedmailto:subscribed@noreply.github.com Objet :[dlemstra/Magick.NET] Linux support? (#74)

Hello,

is it (already) possible to execute Magick.NET within a Linux-environment? My humble tries, to run on Ubuntu 16.04, ended in various Exceptions from the Native-DLL.

If not, a Linux-build should be possible, as far as I can say from the C-Sources?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/dlemstra/Magick.NET/issues/74, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADH_LBbUjXiLm6UQdzbiGsS8ySlXv7jWks5sO5HNgaJpZM4OaP94.

sbrl commented 7 years ago

Hey! I'm glad that Linux support is been considered. I've got a project I wanted to use this in, so once you've got a version on NuGet, I'll gladly help out with testing it :smiley_cat: I currently run Ubuntu Desktop 17.04 with MonoDevelop 6.2 (though I'll be updating soon) and Mono 5.0.1.1.

You've mentioned targeting net20 for mono, but mono actually has good support for .NET 4.5 at least.

stephanbruny commented 7 years ago

Building a NuGet-Package seems a bit tough currently. Porting to Linux has been quite easy actually, but automating the build process and proper testing on both platforms will need a lot more work.

Compiling Magick.NET.Native-Library requires Visual Studio, and C/C++-Linux-Extension. Also the Linux-Version is a seperated Project. As far as I know, it is not possible to have one C++-Project targetting Windows and Linux at the same time with MSVS.

So for now, if you want to use Magick.NET on Linux, you need to cross-compile the Native-Library from my repo, and replace the DLLs in your deployed application. I cannot offer a prebuilt version, because you had to create the exact same environment of all libraries used (libjpeg, zlib, etc. etc.).

Another option is to somehow, get rid of the Native-Library completely, by implementing a FFI-Version in C#...

dlemstra commented 7 years ago

@stephanbruny I'm online on Skype now would like to talk about Linux support with you.

hey-red commented 7 years ago

but automating the build process and proper testing on both platforms will need a lot more work.

Maybe WSL help with this.

dlemstra commented 7 years ago

I just published a new release 7.0.6.600 that has support for running Magick.NET on Linux. Extra instructions can be found here: https://github.com/dlemstra/Magick.NET/blob/master/Documentation/CrossPlatform.md

irfan-yusanif commented 5 years ago

this url is broken, https://github.com/dlemstra/Magick.NET/blob/master/Documentation/CrossPlatform.md

where i can find instructions for linux support

dlemstra commented 5 years ago

The docs have been moved here: https://github.com/dlemstra/Magick.NET/blob/master/docs/CrossPlatform.md. But the documentation needs to be fixed.

sbrl commented 5 years ago

That would probably be a new issue then, I assume

Webreaper commented 7 months ago

Hi, just following up on this (very old) thread. I'm trying to get Magick.Net to build with .Net Core, to be deployed on MacOS, Windows and Linux. Am I right in understanding from the documentation link this is only supported with the Q8 version of Magick.Net, and not the Q16 version?

Or will it work if I add a reference to the Q16-X64 package?

dlemstra commented 7 months ago

That was just an example. You can use any format. Do you have any suggestions to make this more clear in the documentation?