Don't set ImageMagick's 'option' attribute with Graphics::Magick by nschloe · Pull Request #2886 · brucemiller/LaTeXML · GitHub
Skip to content

Don't set ImageMagick's 'option' attribute with Graphics::Magick - #2886

Open
nschloe wants to merge 1 commit into
brucemiller:masterfrom
nschloe:graphicsmagick-no-option
Open

nschloe wants to merge 1 commit into
brucemiller:masterfrom
nschloe:graphicsmagick-no-option

Conversation

@nschloe

@nschloe nschloe commented Oct 7, 2026

Copy link
Copy Markdown

Fixes #2239, and with it the silent exits in #2446 and #2077. It is also what prompted #2705.

When Graphics::Magick is installed, LaTeXML prefers it over Image::Magick, e.g., on Arch, where Inkscape pulls in GraphicsMagick. image_read then sets

image_internalop($image, 'Set', option => 'pdf:use-cropbox=true')

before every image read. option is an Image::Magick attribute; Graphics::Magick doesn't know it (nor define) and raises OptionError (410). PerlMagick's MagickErrorHandler has no error list to report into during Set, so it calls exit(severity % 100), which ends latexml with status 10 and no message. That's why eval {} around the conversion didn't help in #2239. A backtrace at the exit_group:

#2  exit () from /lib/libc.so.6
#3  MagickErrorHandler (severity=OptionError, reason="Unrecognized attribute") at PerlMagick/Magick.xs:105
#4  SetAttribute (..., attribute="option", ...) at PerlMagick/Magick.xs
#5  XS_Graphics__Magick_Set (...) at PerlMagick/Magick.xs:8162

#2077 shows the same thing from the warning side: Exception 410: Unrecognized attribute (option) at .../LaTeXML/Util/Image.pm.

This PR sets the option only for Image::Magick. GraphicsMagick has no crop-box support in its PDF reader to switch on instead, so nothing is lost there.

Note: with this fix, GraphicsMagick no longer crashes, but GraphicsMagick 1.3.48 then writes corrupted PNGs: rows truncated to 3/4 width, color channels shifted. That's a bug in its PNG writer for images with an alpha channel that is fully opaque, which is what Transparent produces for a PDF read without alpha. Minimal reproduction, without LaTeXML:

gm convert -size 300x100 gradient:red-blue -matte bad.png

It is fixed upstream (GraphicsMagick ChangeLog 2026-09-29, SourceForge issue #779 "GraphicsMagick >= 1.3.48 broke png conversion"), but not released yet. Image::Magick doesn't have the problem. Since this is the second GraphicsMagick-only failure, it may be worth preferring Image::Magick when both are installed, as discussed in #2705. I left that out of this PR.

Tested with GraphicsMagick 1.3.48 and ImageMagick 7 both installed: arXiv:1308.6132 (25 PDF figures) died with status 10 before and now converts to HTML; its figures are then hit by the GraphicsMagick PNG bug above, and come out correct with Image::Magick. prove -l t/ gives the same results with and without the patch.

🤖 Generated with Claude Code

Graphics::Magick doesn't know the attribute, and its error handler exits
the process with status 10 (OptionError 410 % 100) without a message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

GraphicsMagick: latexmlc exits with error code 10, no error message

1 participant