How to crop an image using Magick.net while keeping clipping paths if they exist
When cropping images with Magick.net (to remove the white areas around the main image object) and they have a clipping path, then the path is out of sync with the new aspect ratio of the image.
Is there a way to handle this with Magick.Net so that the path is still tracking the objects it was doing before trimming?
(Magick.net uses ImageMagick for image processing, so if anyone knows how to do this in ImageMagick, it might easily "translate" to MagickNet.)
Adding More Information: Here is a link to a simple image with a clipping path in it (I did some strokes in Photoshop and turned it into a path): A zip archive with sample files in different formats containing paths .
And below you will find a piece of code that Magic.Net uses to crop this image with the resulting path movement.
// Put a link to Magick.net-Q8-AnyCPU using "nuget"
using ImageMagick;
using System;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Temp\Path-test-jpg.jpg";
MagickNET.SetGhostscriptDirectory(@"C:\Temp\ConsoleApplication2\bin\Debug");
using (MagickImage image = new MagickImage(path))
{
// DPI
Console.WriteLine(image.Density);
//// Trim
image.Trim();
image.Quality = 99;
image.Write(@"C:\Temp\test-out.jpg");
}
}
}
}
source to share
No one has answered this question yet
Check out similar questions: