Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Image::Magick - Exception 435: unable to open file `Image::Magick::Q16' @ error/Q16.xs/XS_Image__Magick__Q16_Read/13529

by mldvx4 (Friar)
on Jun 06, 2023 at 12:17 UTC ( [id://11152653]=perlquestion: print w/replies, xml ) Need Help??

mldvx4 has asked for the wisdom of the Perl Monks concerning the following question:

An old script has begun giving trouble reading SVG files using Image::Magick, lately. Below is one example which shows this new kind of error. How would I go about figuring how to get past this?

Edit: I should add that the error arises on both Alpine Linux v3.12 and Linux Mint 21.1

#!/usr/bin/perl use Image::Magick; use strict; use warnings; my $image = Image::Magick->new; open(IMAGE, \*DATA); my $err = $image->Read(file=>\*IMAGE); close(IMAGE); if ($err) { print "Error b: $err\n"; exit(1); } print qq(OK\n); exit(0) __DATA__ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 454.22 65.577"><p +ath class="logotype-svg" style="text-align:start" d="M388.22 0c-3.287 + 0-6.357.717-9.22 2.125a23.81 23.81 0 0 0-7.406 5.562c-2.066 2.348-3. +686 5.043-4.906 8.094a26.399 26.399 0 0 0-1.782 9.565c0 3.192.592 6.3 +23 1.72 9.375 1.126 3.05 2.715 5.745 4.78 8.092 2.066 2.348 4.496 4.2 +33 7.313 5.688 2.86 1.455 6.024 2.187 9.5 2.187 3.284 0 6.337-.67 9.1 +54-2.03 2.817-1.41 5.278-3.263 7.344-5.563 2.11-2.347 3.73-5.043 4.90 +5-8.094a25.796 25.796 0 0 0 1.844-9.656c0-3.098-.562-6.152-1.69-9.157 +-1.125-3.05-2.715-5.762-4.78-8.156-2.02-2.392-4.48-4.324-7.344-5.78C3 +94.793.75 391.646 0 388.22 0zm48.124 0c-2.676 0-5.09.296-7.25.906-2.1 +13.564-3.95 1.452-5.5 2.625a11.83 11.83 0 0 0-3.53 4.22c-.8 1.644-1.1 +9 3.53-1.19 5.688 0 2.066.375 3.81 1.126 5.22.75 1.36 1.857 2.53 3.31 +3 3.468 1.502.892 3.293 1.64 5.406 2.25 2.157.563 4.634 1.077 7.404 1 +.594 2.863.562 5.356 1.185 7.47 1.842 2.11.658 3.856 1.468 5.217 2.40 +7 1.363.937 2.344 2.06 3 3.373.66 1.267 1 2.84 1 4.718 0 3.757-1.463 +6.56-4.374 8.44-2.863 1.83-6.774 2.75-11.75 2.75-3.802 0-7.214-.577-1 +0.218-1.75-2.96-1.175-5.685-3.09-8.22-5.72l-1.063.906c2.676 2.676 5.5 +6 4.67 8.657 5.938 3.145 1.22 6.744 1.812 10.78 1.812 5.493 0 9.778-1 +.06 12.876-3.218 3.145-2.16 4.72-5.292 4.72-9.376 0-2.207-.438-4.045- +1.283-5.5s-2.06-2.67-3.656-3.657c-1.55-.985-3.434-1.81-5.687-2.468-2. +254-.658-4.762-1.25-7.53-1.814-2.77-.563-5.17-1.124-7.19-1.687-1.97-. +61-3.607-1.328-4.874-2.126-1.268-.845-2.203-1.858-2.814-3.032-.61-1.2 +2-.906-2.716-.906-4.5 0-1.83.297-3.482.908-4.937.61-1.454 1.59-2.685 +2.906-3.72 1.314-1.077 2.98-1.903 5-2.467 2.065-.563 4.51-.843 7.375- +.843 2.955 0 5.51.39 7.623 1.187 2.16.8 4.216 2.28 6.187 4.44l.908-.9 +7c-1.972-2.16-4.138-3.702-6.532-4.594C442.31.466 439.536 0 436.344 0z +M42.406.594V44.47c0 3.097 2.042 5.75 5.563 5.75h3.185l-.03-1.345c-.07 + 0-1.162.03-3.063.03-2.747 0-4.22-2.394-4.22-4.436V.592h-1.437zm194.8 +44 0v44c0 3.38 2.933 5.625 6.313 5.625 3.872 0 4.335.07 4.406 0v-1.41 +h-4.408c-2.465 0-4.696-1.472-4.907-4.218V14.75h10.188v-1.406h-10.188V +.594h-1.406zm150.97.812c3.097 0 5.964.655 8.592 1.97a22.113 22.113 0 +0 1 6.97 5.343c1.97 2.204 3.513 4.775 4.593 7.685a24.2 24.2 0 0 1 1.6 +88 8.938c0 2.957-.546 5.886-1.625 8.75A24.424 24.424 0 0 1 404 41.748 +c-1.878 2.252-4.184 4.09-6.906 5.5-2.676 1.36-5.636 2.03-8.875 2.03-3 +.194 0-6.108-.654-8.784-1.97a21.838 21.838 0 0 1-6.906-5.28 26.811 26 +.811 0 0 1-4.592-7.656 25.784 25.784 0 0 1-1.625-9.03c0-2.96.53-5.856 + 1.562-8.72 1.08-2.863 2.575-5.434 4.5-7.688 1.925-2.253 4.23-4.044 6 +.906-5.406 2.725-1.407 5.7-2.124 8.94-2.124zm-74.314 1.28c-.803.05-1. +614.26-2.312.658a4.932 4.932 0 0 0-2.25 2.812c-.242.802-.233 1.666-.1 +56 2.5.085.928.264 1.826.53 2.72.198.66.457 1.3.72 1.936-1.03.005-2.0 +65.028-3.094.032-.25.004-2.197.022-3.188.312-5.243 1.537-8.483 4.27-1 +0.97 9.125l.002-9.435h-1.407v36.53h1.41V26.782c.914-3.343 2.604-6.266 + 5-8.405 2.393-2.14 5.485-3.484 9.217-3.625 1.15-.046 2.384-.047 3.56 +3-.063l16.374 35.187c-5.563 12.674-5.773 13.11-6.125 13.53-.495.494-1 +.06.75-3.315.75l-1.25-.03v1.406l1.25.032c2.606 0 4.015-.552 4.72-1.75 +l.5-.843 21.75-49.626h-1.563l-15.282 34.78-15.405-33.468c.745-.01 1.5 +1.037 2.25-.062.8-.107 1.56-.427 2.25-.844.724-.437 1.372-.976 1.875- +1.656.7-.946 1.062-2.137 1.094-3.313.027-.997-.17-1.986-.625-2.874a5. +954 5.954 0 0 0-1.47-1.813 6.049 6.049 0 0 0-2.626-1.282 5.79 5.79 0 +0 0-1.438-.125h-.03zm.438 1.158c.78.008 1.552.298 2.187.75.638.45 1.1 +48 1.087 1.5 1.78.44.862.646 1.85.565 2.813-.082.964-.43 1.895-1.063 +2.625a4.482 4.482 0 0 1-3.655 1.5h-1.813L311.47 12a13.191 13.191 0 0 +1-.783-2.625c-.175-.918-.31-1.88-.062-2.78.248-.904.888-1.64 1.688-2. +126.613-.375 1.313-.635 2.03-.627zM212.688 12.75c-10.28 0-14.188 9.38 +8-14.188 16.78v20.345h1.406V29.53c0-7.674 4.19-15.374 12.78-15.374 8. +592 0 12.75 7.7 12.75 15.375v20.346h1.408V29.53c0-7.392-3.876-16.78-1 +4.156-16.78zm-195.72.03C6.76 12.78.283 21.93 0 31.72c0 9.364 7.384 18 +.874 17.594 18.874 5.492 0 12.278-3.047 14.53-8.75h-1.53c-2.183 4.788 +-7.65 7.343-13 7.343-8.943 0-15.554-7.91-16.188-16.78h33.438v-.75c-.1 +4-10-7.172-18.876-17.875-18.876zm55.25 0c-10.21 0-16.686 9.15-16.968 +18.94 0 9.364 7.415 18.874 17.625 18.874 5.492 0 12.247-3.047 14.5-8. +75h-1.5c-2.183 4.788-7.65 7.343-13 7.343-8.942 0-15.585-7.91-16.22-16 +.78h33.47v-.75c-.14-10-7.203-18.876-17.906-18.876zm37.813 0c-5.983 0- +10.692 4.583-12.123 10.19-.7 2.738-.937 3.63-.937 26.905h1.405c0-20.4 +86.054-22.017.438-24.813.897-5.91 5.075-10.935 11.218-10.875 6.56 0 1 +2.87 4.226 12.5 15.47 0 2.993.096 8.145.096 11.968 0 4.284-.094 8.25- +.094 8.25h1.407s.15-13.597 0-20.22c-.245-10.665 5.52-15.455 11.906-15 +.468 6.653.1 11.758 5.12 12.156 12.094.202 3.537.094 17.597.094 23.59 +6h1.406c0-23.335-.228-24.368-.72-26.844-1.046-5.278-6.27-10.25-12.936 +-10.25-6.934 0-11.96 5.04-12.438 10.626-.563-5.633-6.545-10.625-13.37 +5-10.625zm63.658 0c-10.21 0-16.687 9.15-16.968 18.94 0 9.364 7.414 18 +.874 17.624 18.874 5.492 0 12.247-3.047 14.5-8.75h-1.5c-2.183 4.788-7 +.65 7.343-13 7.343-8.943 0-15.585-7.91-16.22-16.78h33.47v-.75c-.14-10 +-7.204-18.876-17.906-18.876zm95.188 0c-4.506 0-8.854 2.177-12.656 4.7 +82l.842 1.125c4.084-2.886 8.292-4.5 11.813-4.5 7.253 0 11.97 5.193 11 +.97 12.657V31c-1.902-.704-6.266-2.03-12.25-2.03-6.338 0-15.064 2.52-1 +5.064 10.405 0 6.267 5.227 11.22 11.846 11.22 5.703 0 11.737-2.12 15. +47-6.908v3.375c0 1.48.91 2.743 2.53 2.813h1.406V48.47h-1.405c-.775 0- +.984-.563-1.125-1.408V26.844c0-7.887-4.573-14.063-13.375-14.063zM16.9 +7 14.188c9.364 0 15.77 7.307 16.405 16.813H1.405C1.83 22.975 7.322 14 +.19 16.97 14.19zm55.25 0c9.364 0 15.77 7.307 16.405 16.813h-31.97c.42 +4-8.026 5.917-16.812 15.564-16.812zm101.468 0c9.364 0 15.772 7.307 16 +.406 16.813h-31.97c.423-8.026 5.917-16.812 15.564-16.812zm94.906 16.1 +88c4.084 0 8.236.638 12.25 2.187v7.25c0 .845-.327 1.82-1.03 2.875-2.8 +88 4.507-9.088 6.5-14.44 6.5-5.42 0-10.437-3.897-10.437-9.812 0-6.83 +7.672-9 13.657-9z" fill="currentColor"/></svg>
  • Comment on Image::Magick - Exception 435: unable to open file `Image::Magick::Q16' @ error/Q16.xs/XS_Image__Magick__Q16_Read/13529
  • Download Code

Replies are listed 'Best First'.
Re: Image::Magick - Exception 435: unable to open file `Image::Magick::Q16' @ error/Q16.xs/XS_Image__Magick__Q16_Read/13529
by hv (Prior) on Jun 06, 2023 at 13:19 UTC

    My starting point would always be to (try to) get a stack trace, by inserting something like the following before the call that dies:

    use Carp; local $SIG{__DIE__} = sub { Carp::confess(@_) };

    That would give additional diagnostic information to help you or others figure out what's going on.

    It isn't clear exactly what is happening when you run the script though - does it die with the error message in the title, or does it reach your print "Error b: $err\n"; line? It would also be useful to know the version numbers for perl and for Image::Magick - I assume something getting upgraded is what introduced the problem.

    Searching around a bit, there appear to be two distinct versions of the Image::Magick module: one provided on CPAN (currently at version 7.1.0-0), another provided as a stub as part of the ImageMagick library distribution (on github here). The filename in your error message suggests you are using the library distribution, which may make it a bit harder to diagnose.

      Thanks.

      Yes the script gets to the print "Error b: $err\n"; line, which shows the output:

      Error b: Exception 435: unable to open file `Image::Magick::Q16' @ error/Q16.xs/XS_Image__Magick__Q16_Read/13529

      That's even after adding the CARP lines to the beginning of the script as you've recommended. So adding CARP provides no additional output.

      On the one system,

      $ apt-cache policy libimage-magick-perl | head -n 3 libimage-magick-perl: Installed: 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 Candidate: 8:6.9.11.60+dfsg-1.3ubuntu0.22.04.3 $ apt-cache policy perl | head -n 3 perl: Installed: 5.34.0-3ubuntu1.2 Candidate: 5.34.0-3ubuntu1.2

      On the other system,

      $ apk list imagemagick-perlmagick imagemagick-perlmagick-7.1.1.11-r3 x86_64 {imagemagick} (ImageMagick) +[installed] $ apk list | grep ^perl-5 perl-5.36.1-r2 x86_64 {perl} (Artistic-Perl OR GPL-1.0-or-later) [inst +alled]
      Edit: updated with Perl versions

        Hmm, I had a little dig, and I'm not getting very far: the internal structure of the code is, um, unusual. You are probably best off opening an issue on github, but be warned that the maintainers are a small team that appear to be somewhat swamped.

        I note that you have not mentioned the version of perl: they will likely want that alongside the other version numbers you have mentioned.

Re: Image::Magick - Exception 435: unable to open file `Image::Magick::Q16' @ error/Q16.xs/XS_Image__Magick__Q16_Read/13529
by Anonymous Monk on Jun 07, 2023 at 12:22 UTC

    Your script gives same error under Win32 and Strawberry; I installed latest IM 7.1.1-11 and then Image::Magick. Though they specifically warn:

    Note, reading from or writing to a Perl filehandle may fail under Windows

    maybe this plague has spread to Linux lately.

    Reading from file (providing a filename) works. And this also works:

    my $i = Image::Magick-> new( magick => 'svg' ); $i-> BlobToImage( do { undef $/; <DATA> } ); $i-> Write( 'junk.png' ); # to test

      Thanks. I gave it a try and switched from using a file handle to using just a file name and still get an an error, albeit a different one:

      Error b: Exception 430: unable to open file '/tmp/magick-K306MFDJ8ArD4Ytnu0O7O3MOC9CghbHa': No such file or directory @ error/constitute.c/ReadImage/785

      I'm not creating any temporary files there, so it must be the module which is trying to do that. It looks like the temporary file vanishes before it is used.

Re: Image::Magick - Exception 435: unable to open file `Image::Magick::Q16' @ error/Q16.xs/XS_Image__Magick__Q16_Read/13529
by kcott (Archbishop) on Jun 08, 2023 at 13:08 UTC

    G'day mldvx4,

    As I'm not a user of Image::Magick, I left responses to those with more knowledge; however, I see after two days you still have no resolution, so here's some suggestions.

    Image::Magick has minimal documentation and points to "PerlMagick Image API for Perl". That appears to be rather dated ("Copyright © 1999") and has Perl code of a similar vintage. It has various issues such as no I/O exception handling and use of a package variable for a filehandle. It looks like your posted code is based on this.

    I'd probably write it more like this:

    #!/usr/bin/perl use strict; use warnings; use autodie; # for I/O exception handling use Image::Magick; my $svg_filename = '/path/to/some.svg'; my $image = Image::Magick::->new(); open my $fh, '<', $svg_filename; my $err = $image->Read(file => $fh); if ($err) { print "Error b: $err\n"; exit 1; } close $fh; # moved after any code related to $fh print "OK\n"; exit 0;

    You said: "I gave it a try and switched from using a file handle to using just a file name ...". I don't know how you implemented that in code; I've used both a filehandle ($fh) and a filename ($svg_filename).

    Do note that is untested code: I don't have Image::Magick installed.

    — Ken

Re: Image::Magick - Exception 435: unable to open file `Image::Magick::Q16' @ error/Q16.xs/XS_Image__Magick__Q16_Read/13529
by Anonymous Monk on Jun 07, 2023 at 07:13 UTC
    File has leading whitespace, xml/svg don't allow that?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11152653]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found