Magick.NET
| Language | C# (.NET and .NET Standard 2.0) |
|---|---|
| License | Apache 2.0 (ImageMagick license for the native part; Ghostscript, needed to read EPS, is AGPL-3.0) |
| Repository | github.com/dlemstra/Magick.NET |
| Documentation | docs in the repository |
| Depends on | native ImageMagick (bundled in the NuGet package); Ghostscript installed separately for reading EPS |
| Read / write | yes (through Ghostscript) / yes (raster image wrapped in EPS) |
Magick.NET reads an EPS file by calling Ghostscript, which renders the graphic at the Density you set; the image is cropped to the bounding box. The result is a normal MagickImage you can resize, convert or composite. Writing EPS works without Ghostscript but produces a raster image inside a PostScript wrapper, not vector art.
Installation#
Shell
dotnet add package Magick.NET-Q8-AnyCPU
Install Ghostscript (same bitness as your process), or copy its DLL next to your app and call MagickNET.SetGhostscriptDirectory(path).
Basic usage: convert EPS to PNG#
C#
using ImageMagick;
var settings = new MagickReadSettings
{
Density = new Density(300), // dpi used to rasterize the vector art
};
using var image = new MagickImage("logo.eps", settings);
Console.WriteLine($"{image.Width} x {image.Height} px");
image.Write("logo.png");
How to convert EPS to a JPEG of a given width#
Render at a high density, then resize down for smooth edges:
C#
var settings = new MagickReadSettings { Density = new Density(300) };
using var image = new MagickImage("logo.eps", settings);
image.BackgroundColor = MagickColors.White;
image.Alpha(AlphaAction.Remove); // JPEG has no transparency
image.Resize(800, 0); // 800 px wide, keep aspect ratio
image.Quality = 90;
image.Write("logo.jpg");
How to get the size of an EPS graphic#
Ping reads the header without rendering. At the default 72 dpi one pixel is one point:
C#
using var image = new MagickImage();
image.Ping("logo.eps");
Console.WriteLine($"{image.Width} x {image.Height} pt");
How to save an image as EPS#
C#
using var image = new MagickImage("photo.jpg");
image.Write("photo.eps", MagickFormat.Eps3); // Level 3, compressed
MagickFormat.Ept writes EPS with a TIFF preview in the binary header, for programs that only show previews.
Tips#
- For EPS to PDF with vectors kept, use Ghostscript (
pdfwrite) through Ghostscript.NET; Magick.NET would rasterize it. - CMYK EPS files come out as CMYK images; set
settings.ColorSpace = ColorSpace.sRGBbefore reading to get RGB.