Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magick.NET with WebAPI - Visual Studio 2022 - windows & docker - IIS express error #1597

Open
JBaltika opened this issue Mar 24, 2024 · 1 comment

Comments

@JBaltika
Copy link

Magick.NET version

.net 8.0 with latest ImageMagick libraries

Environment (Operating system, version and so on)

Visual Studio 2022 - windows & docker - IIS express

Description

Hi,
I am doing my first project/POC with Magic.NET and getting an error in web API project .NET 8.0. It's a simple WebAPI template (WeatherForecast) , with add Magick.NET.Core library. We need to generate UMl for Swagger documentation, so we just need to generate some text on the image, nothing special. I check some examples, using imagexxx.Read( "caption: or "label: syntax. to generate text. Can anybody point me to the right direction on how to figure out why I am getting this error in WebAPI, but the code runs fine and generates an image

[Route("images")]
[ApiController]
public class UmlImageController : ControllerBase
{
    [Route("uml", Name = "GenarateUmlImage")]
    [HttpGet]
    public ActionResult GenarateUml([FromQuery] string fullType)
    {
        using (var images = new MagickImageCollection())
        {
            var umlClassSettings = new MagickReadSettings
            {
                FontFamily = "Arial",
                FontPointsize = 14,
                FontWeight = FontWeight.Bold,
                BackgroundColor = MagickColors.AntiqueWhite,
                Format = MagickFormat.Png
            };

            var classType = typeof(ImageContentFilesJsonResponseMessage);
            var headerImage = new MagickImage();
            headerImage.Read($"caption:{classType.Name}", umlClassSettings); // This line is failing in web app, but in fine in UnitTest
            headerImage.Extent(headerImage.BaseWidth + 40, headerImage.BaseHeight + 20, Gravity.Center);
            images.Add(headerImage);
ImageMagick.MagickBlobErrorException: UnableToOpenBlob 'caption:ImageContentFilesJsonResponseMessage': No such file or directory @ error/blob.c/OpenBlob/3571
   at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result) in /_/src/Magick.NET/Native/NativeInstance.cs:line 57
   at ImageMagick.MagickImage.NativeMagickImage.ReadFile(IMagickSettings`1 settings) in /_/src/Magick.NET/Native/MagickImage.cs:line 6983
   at ImageMagick.MagickImage.Read(String fileName, IMagickReadSettings`1 readSettings, Boolean ping) in /_/src/Magick.NET/MagickImage.cs:line 7687
   at ImageMagick.MagickImage.Read(String fileName, IMagickReadSettings`1 readSettings) in /_/src/Magick.NET/MagickImage.cs:line 4970
   at ImageMagickWebApplication.Controllers.UmlImageController.GenarateUml(String fullType)
    <PropertyGroup>
        <MagickCopyNativeWindows>true</MagickCopyNativeWindows>
        <MagickCopyNativeLinux>true</MagickCopyNativeLinux>
        <MagickCopyNativeLinuxMusl>true</MagickCopyNativeLinuxMusl>
        <MagickCopyNativeMacOS>false</MagickCopyNativeMacOS>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Magick.NET-Q8-x64" Version="13.6.0" />
        <PackageReference Include="Magick.NET.Core" Version="13.6.0" />
        <PackageReference Include="Magick.NET.SystemDrawing" Version="7.2.2" />

Steps to Reproduce

Create a template WebAPI .NET project add libraries and controller with code something like this

        using (var images = new MagickImageCollection())
        {
            var umlClassSettings = new MagickReadSettings
            {
                FontFamily = "Arial",
                FontPointsize = 14,
                FontWeight = FontWeight.Bold,
                BackgroundColor = MagickColors.AntiqueWhite,
                Format = MagickFormat.Png
            };

            var headerImage = new MagickImage();
            headerImage.Read($"caption:ImageContentFilesJsonResponseMessage", umlClassSettings); // This line is failing in web app, but in fine in UnitTest
            headerImage.Extent(headerImage.BaseWidth + 40, headerImage.BaseHeight + 20, Gravity.Center);
            images.Add(headerImage);

and

@dlemstra
Copy link
Owner

No idea why this works in a unit test but you are setting Format to MagickFormat.Png in the umlClassSettings. This means the Read method expects to read an image in the Png format instead of the Caption format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants