Installation

  • You have two options to get the Magick.NET binaries in your project.
    • Use the zip files:
      • Download the latest release and unpack the files for your .NET version and platform into the bin directory of your project.
      • Add a reference to Magick.NET-(Q8/Q16/Q16-HDIR).dll.
    • Use NuGet:
      • Right click on the references of your project and choose 'Manage NuGet packages'.
      • Search for Magick.NET and choose the package that uses the platform of your choice: x86/x64 or AnyCPU.
  • If you want to convert an AI/EPS/PDF/PS file you need to install Ghostscript

Q8, Q16 or Q16-HDRI?

Versions with Q8 in the name are 8 bits-per-pixel component (e.g. 8-bit red, 8-bit green, etc.), whereas, Q16 are 16 bits-per-pixel component. A Q16 version permits you to read or write 16-bit images without losing precision but requires twice as much resources as the Q8 version. The Q16-HDRI version uses twice the amount of memory as the Q16. It is more precise because it uses a floating point (32 bits-per-pixel component) and it allows out-of-bound pixels (less than 0 and more than 65535). The Q8 version is the recommended version. If you need to read/write images with a better quality you should use the Q16 version instead.

AnyCPU

The AnyCPU version of Magick.NET is designed to allow your application to be used in a 32 bit or a 64 bit environment. When one of the classes in the library is used it will detect if the application pool is 32 or 64 bit. It will then read the x86 or the x64 version of the dll from an embedded resource. This resource is written to a temporary directory to improve the start up time the next it is used. You can change the directory that is used with the CacheDirectory property of the MagickAnyCPU class when the default directory is causing issues in your production environment.

MagickAnyCPU.CacheDirectory = @"C:\MyProgram\MyTempDir";

You should install the x86 and the x64 version of the Visual C++ Redistributable on the machine you will be using because you don't know if the x86 or the x64 will be used. If you do you are probably better of using the x86 or the x64 version of Magick.NET.

.NET Core

Starting with version 7.0.0.0102 support for .NET Core was added. This currently only works on Windows. If you want to use the library you should add a dependency to your project.json file. The .NET Core version can be found on NuGet with the name Magick.NET.Core-(Q8/Q16/Q16-HDRI). Below is an example for the Q8 version of Magick.NET.Core. When you search for this package on NuGet you will also find a Native version. This is used by this package to execute the ImageMagick code.

"dependencies":
{
  "Magick.NET.Core-Q8": "7.0.0.0102"
}

ImageMagick 7

Magick.NET is linked with ImageMagick 7 that is currently in beta. Most examples on the Internet use ImageMagick 6 so there could be some minor differences in syntax. The biggest difference between 6 and 7 is that the latter uses Alpha instead of Opacity. You can find some more information about ImageMagick 7 here: http://www.imagemagick.org/script/porting.php.

Ghostscript

You only need to install Ghostscript if you want to convert EPS/PDF/PS files. Make sure you only install the version of GhostScript with the same platform. If you use the 64-bit version of Magick.NET you should also install the 64-bit version of Ghostscript. You can use the 32-bit version together with the 64-version but you will get a better performance if you keep the platforms the same. Ghostscript can be downloaded here: http://www.ghostscript.com/download/gsdnld.html. If you don't want to install Ghostscript on your machine you can copy gsdll32.dll/gsdl64.dll and gswin32c.exe/gswin64c.exe to your server and tell Magick.NET where the file is located with the code below.

MagickNET.SetGhostscriptDirectory(@"C:\MyProgram\Ghostscript");

Be aware that you need a license if you want to use Ghostscript commercially.

Initialization

Because Magick.NET embeds all the ImageMagick files you don't need to initialize the library. You can however decide to use your own xml configuration files. See below for an example:

using System;
using ImageMagick;

namespace MagickExample
{
   internal class Program
   {
      internal static void Main(string[] args)
      {
         MagickNET.Initialize(@"C:\MyProgram\MyImageMagickXmlFiles");
      }
   }
}

Temporary directory

ImageMagick sometimes needs to write temporary files to the hard drive. The default folder for this is %TEMP% but the folder change be changed with the following code:

MagickNET.SetTempDirectory(@"C:\MyProgram\MyTempFiles");

Examples

Below here you can find some examples on how to use Magick.NET. Because Magick.NET comes with a xml documentation file IntelliSense will also provide you with some help on how to use Magick.NET.

Magick.NET.Web

Magick.NET.Web is an extension to Magick.NET that can be used to script/optimize/compress image with an IHttpModule. The documentation for the library can be found here: Magick.NET.Web.

More documentation

For some great ImageMagick examples please visit the following page: http://www.imagemagick.org/Usage. Start a new discussion if you need help to change one of these examples into code.


Last edited Oct 20, 2016 at 8:10 PM by dlemstra, version 49