ropensci / magick

Magic, madness, heaven, sin
https://docs.ropensci.org/magick
Other
456 stars 63 forks source link

librsvg delegate broken on Windows #380

Closed jeroen closed 11 months ago

jeroen commented 1 year ago

The new windows build has imagemagick 6.9.12.93 + librsvg support (MAGICKCORE_RSVG_DELEGATE is defined).

However when we try to read a svg file, it errors because it is trying to shell out to inkscape??

FailedToExecuteCommand `"inkscape" "C:/Users/MVANKE~1/AppData/Local/Temp/Rtmpgl4egq/magick-oemwWIo73_IpcGUWlDJkP8HuJTcMIhhV" --export-png="C:/Users/MVANKE~1/AppData/Local/Temp/Rtmpgl4egq/magick-yfIMxqUjjGE_ndYBRSln9XxuvbzvScyH.png" --export-dpi="96" --export-background="rgb(100%,100%,100%)" --export-background-opacity="1" > "C:/Users/MVANKE~1/AppData/Local/Temp/Rtmpgl4egq/magick-w28sYjpi17u5g_0XAvY3ly-be32rVATx" 2>&1' (-1) @ error/delegate.c/ExternalDelegateCommand/514

@dlemstra any idea why this would happen?

dlemstra commented 1 year ago

Does this only happen with a specific file or with every svg file? And is it possible to share that file?

jeroen commented 1 year ago

It happens for all svg files. It is as if imagemagick does not know that it has librsvg, but it does. This did not happen in our previous build from 2 years ago (6.9.12-3).

Here is an example svg: http://jeroen.github.io/images/tiger.svg

dlemstra commented 1 year ago

Are you using our visual studio build or the MSYS2 one? We don't maintain the MSYS2 one.

jeroen commented 1 year ago

This is our own ming-w64 build, with gcc compilers similar to msys2. The configuration should be the same as other unix systems though.

Where does the svg delegate get selected?

dlemstra commented 1 year ago

I am not familiar with the msys2 setup and how this selects dependencies. But librsvg switched to another language maybe you don't have the tooling for that installed?

jeroen commented 1 year ago

No that's not the issue, I am sure the build is fine. The librsvg library works and is compiled and linked to imagemagick, and the MAGICKCORE_RSVG_DELEGATE macro is enabled. The build log is here: https://github.com/r-windows/rtools-packages/actions/runs/5776178439/job/15655011317. It includes:

-------------------------------------------------------------
checking for librsvg-2.0 >= 2.9.0... yes
checking for cairo-svg... yes
...
...
  DELEGATES       = bzlib fftw freetype heic jng jpeg lcms lzma openjp2 pango png ps raw rsvg tiff webp xml zlib zstd

However somehow there seems a bug in imagemagick that librsvg is not used when reading an svg file on Windows, even though it is available. It worked for our previous build...

Could it be that something changed on how imagemagick decides which delegate to use for a given format?

jeroen commented 1 year ago

Can you maybe point me to the code in imagemagick where image.read chooses a delegate based on the input file (extension)? Maybe I can bisect where the change happened..

jeroen commented 1 year ago

This is a shot in the dark, but could it be that this commit disables the rsvg coder when used from C++ (which wraps around BlobToImage):

dlemstra commented 1 year ago

That doesn't disables it. It means that the svg cannot be read from a byte array but must be read from a file instead. Maybe your delegates.xml got inkscape configured for some reason?

jeroen commented 1 year ago

We don't use any delegates.xml because we configure imagemagick with --enable-zero-configuration.

jeroen commented 1 year ago

Here is some output if we set MAGICK_DEBUG=all

2023-08-11T18:43:56+00:00 0:02.839 0.094u 6.9.12 Policy rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/policy.c/IsRightsAuthorized/633/Policy
  Domain: Module; rights=Unrecognized; pattern="SVG" ...
2023-08-11T18:43:56+00:00 0:02.839 0.094u 6.9.12 Policy rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/policy.c/IsRightsAuthorized/633/Policy
  Domain: Path; rights=Read; pattern="C:\Users\Jeroen\AppData\Local\Temp\RtmpUDpj1w\file77879e82db0.svg" ...
2023-08-11T18:43:56+00:00 0:02.840 0.094u 6.9.12 Blob rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/blob.c/OpenBlob/2842/Blob
    read 3 magic header bytes
2023-08-11T18:43:56+00:00 0:02.840 0.094u 6.9.12 Cache rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/cache.c/DestroyPixelCache/1197/Cache
  destroy 
2023-08-11T18:43:56+00:00 0:02.841 0.094u 6.9.12 Policy rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/policy.c/IsRightsAuthorized/633/Policy
  Domain: Coder; rights=Read; pattern="SVG" ...
2023-08-11T18:43:56+00:00 0:02.841 0.094u 6.9.12 Policy rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/policy.c/IsRightsAuthorized/633/Policy
  Domain: Path; rights=Read; pattern="C:\Users\Jeroen\AppData\Local\Temp\RtmpUDpj1w\file77879e82db0.svg" ...
2023-08-11T18:43:56+00:00 0:02.842 0.094u 6.9.12 Blob rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/blob.c/OpenBlob/2842/Blob
    read 3 magic header bytes
2023-08-11T18:43:56+00:00 0:02.842 0.094u 6.9.12 Configure rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/delegate.c/LoadDelegateCache/2162/Configure
  Loading delegate configuration file "built-in" ...
2023-08-11T18:43:56+00:00 0:02.843 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireUniqueFileResource/633/Resource
  ...
2023-08-11T18:43:56+00:00 0:02.844 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireUniqueFileResource/690/Resource
  Acquire C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-d10jRRjuZiVxdU2wqY5D-bT84qDz9Zkp
2023-08-11T18:43:56+00:00 0:02.845 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireUniqueFileResource/633/Resource
  ...
2023-08-11T18:43:56+00:00 0:02.845 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireUniqueFileResource/690/Resource
  Acquire C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-LRiK--AjydTQsQDwtHW_cctGybUGDSC2
2023-08-11T18:43:56+00:00 0:02.845 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireUniqueFileResource/633/Resource
  ...
2023-08-11T18:43:56+00:00 0:02.846 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireUniqueFileResource/690/Resource
  Acquire C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-nqU5GwrxIbX3o4MmhtjBDvOFSiI2fWhl
2023-08-11T18:43:56+00:00 0:02.846 0.094u 6.9.12 Policy rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/policy.c/IsRightsAuthorized/633/Policy
  Domain: Delegate; rights=Execute; pattern="inkscape" ...
2023-08-11T18:43:56+00:00 0:02.848 0.094u 6.9.12 Configure rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/locale.c/LoadLocaleCache/1206/Configure
  Loading locale configure file "built-in" ...
2023-08-11T18:43:56+00:00 0:02.848 0.094u 6.9.12 Exception rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/delegate.c/ExternalDelegateCommand/514/Exception
  FailedToExecuteCommand `"inkscape" "C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-d10jRRjuZiVxdU2wqY5D-bT84qDz9Zkp" --export-png="C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-LRiK--AjydTQsQDwtHW_cctGybUGDSC2.png" --export-dpi="96" --export-background="rgb(100%,100%,100%)" --export-background-opacity="1" > "C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-nqU5GwrxIbX3o4MmhtjBDvOFSiI2fWhl" 2>&1' (-1)
2023-08-11T18:43:56+00:00 0:02.849 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/RelinquishUniqueFileResource/1302/Resource
  Relinquish C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-nqU5GwrxIbX3o4MmhtjBDvOFSiI2fWhl
2023-08-11T18:43:56+00:00 0:02.850 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/RelinquishUniqueFileResource/1302/Resource
  Relinquish C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-d10jRRjuZiVxdU2wqY5D-bT84qDz9Zkp
2023-08-11T18:43:56+00:00 0:02.851 0.094u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/RelinquishUniqueFileResource/1302/Resource
  Relinquish C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-LRiK--AjydTQsQDwtHW_cctGybUGDSC2.png
2023-08-11T18:43:56+00:00 0:02.861 0.109u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireMagickResource/439/Resource
  Area: 810000B/810000B/10.2666GB
2023-08-11T18:43:56+00:00 0:02.861 0.109u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/AcquireMagickResource/439/Resource
  Memory: 6.17981MiB/6.17981MiB/2.39038GiB
2023-08-11T18:43:56+00:00 0:02.861 0.109u 6.9.12 Cache rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/cache.c/OpenPixelCache/4017/Cache
  open C:\Users\Jeroen\AppData\Local\Temp\RtmpUDpj1w\file77879e82db0.svg[0] (Heap Memory, 900x900 6.17981MiB)
2023-08-11T18:43:56+00:00 0:02.927 0.156u 6.9.12 Exception rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/constitute.c/ReadImage/651/Exception
  Coder (SVG) generated an image despite an error (415), notify the developers
Error: rsession-utf8.exe: FailedToExecuteCommand `"inkscape" "C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-d10jRRjuZiVxdU2wqY5D-bT84qDz9Zkp" --export-png="C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-LRiK--AjydTQsQDwtHW_cctGybUGDSC2.png" --export-dpi="96" --export-background="rgb(100%,100%,100%)" --export-background-opacity="1" > "C:/Users/Jeroen/AppData/Local/Temp/RtmpUDpj1w/magick-nqU5GwrxIbX3o4MmhtjBDvOFSiI2fWhl" 2>&1' (-1) @ error/delegate.c/ExternalDelegateCommand/514
2023-08-11T18:43:56+00:00 0:02.944 0.172u 6.9.12 Cache rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/cache.c/DestroyPixelCache/1197/Cache
  destroy C:\Users\Jeroen\AppData\Local\Temp\RtmpUDpj1w\file77879e82db0.svg[0]
2023-08-11T18:43:56+00:00 0:02.945 0.172u 6.9.12 Resource rsession-utf8.exe[1912]: ../ImageMagick-6.9.12-93/magick/resource.c/RelinquishMagickResource/1263/Resource
  Memory: 6.48MB/0B/2.39038GiB
dlemstra commented 1 year ago

Can you reproduce this on the command line? You will probably need to bisect our commits and find the one that broke your setup.

And about that commit you referenced earlier. Disabling blob support doesn't really make sense to me. And it also looks like we didn't apply this patch in IM7. But I don't understand how that commit could break your setup.

jeroen commented 11 months ago

Fixed upstream: https://github.com/ImageMagick/ImageMagick6/issues/274