Reputation: 29
I am using .Net Core. In one of the service application, I am using ImageMagick. Nuget package Magick.NET-Q16-AnyCPU 7.14.3. When I run this service locally on windows, the below mention last log statement returns count as 1, which is correct, while when I run the same service under docker, then the last log statement returns 0. I think I am missing some setting that needs to be done for the docker environment. Can someone suggest?
public ImageModel CreatePDFPreview(Stream stream)
{
_logger.Information("Creating PDF preview for stream of size {size}", stream.Length);
var settings = new MagickReadSettings();
settings.Density = new Density(300, 300);
using (var images = new MagickImageCollection())
{
stream.Position = 0;
images.Read(stream, settings);
_logger.Information("Images created for the stream, total {count}", images.Count);
}
}
When I am running the service in docker, I am not getting any exception, just that images.Count
is returned as 0
.
As suggested in one of the posts, I added this in my project file, bit no luck.
<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" Version="7.14.3" />
</ItemGroup>
Upvotes: 2
Views: 2214
Reputation: 5895
I was daces a same issue with Magick.Net
deployed in docker. @Nesaje assumption about about missing GhostScript
library helped me to find solution. I added ghostscript in Dockerfile
with command:
RUN apt update -y && apt install -y ghostscript
Upvotes: 3
Reputation: 595
Any chance you're missing GhostScript in a docker environment and have it in local environment? This tool is requirement for Magick.Net to convert PDFs to images. Check Convert PDF docs for more info. If I understand, you're reading PDF stream and trying to convert it into an image?
Also, please check comment about Ghostscript on Magick.Net github.
Make sure to match platform of your Magick.NET (32 or 64 bit). There is also an option to set path to Ghostscript directory if only dlls are copied over like:
MagickNET.SetGhostscriptDirectory(@"C:\MyProgram\Ghostscript");
There is also warning about license which is required if Ghsotscript is intended for commercial use.
Upvotes: 4