7

When I try to load an SVG file, I get this error message

Fatal error: Uncaught exception 'ImagickException' with message
'unable to open file `/tmp/magick-aWsnhHLT': No such file or directory
 @ error/constitute.c/ReadImage/583'
in /var/www/file.php:250
Stack trace:
#0 /var/www/file.php(250): Imagick->readimage('/var/www/ima...')
#1 {main} thrown in /var/www/file.php on line 250

And that's with this code

$Vector = new Imagick();
$Vector->readimage("$_SERVER[DOCUMENT_ROOT]/images/Vector.svg");

And this SVG file

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
 width="59.760000pt" height="71.520000pt" viewBox="0 0 59.760000 71.520000"
 preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.11, written by Peter Selinger 2001-2013
</metadata>
<g transform="translate(0.000000,71.520000) scale(0.024000,-0.024000)"
fill="#ffffff" stroke="none">
<path d="M1367 2540 c-7 0 -30 -9 -52 -21 -22 -12 -52 -34 -67 -51 -21 -21
-28 -40 -28 -68 0 -22 5 -50 12 -64 6 -14 21 -32 34 -41 22 -14 23 -14 17 20
-3 18 -3 46 1 60 4 14 15 34 26 45 11 11 33 20 48 20 18 0 38 -10 53 -26 18
-19 24 -37 24 -69 0 -32 -6 -50 -25 -70 -21 -22 -22 -28 -10 -35 8 -5 27 -10
41 -10 21 0 30 7 40 33 8 17 14 58 13 89 -1 38 -8 67 -20 85 -10 15 -24 40
-31 56 -7 15 -24 32 -38 37 -15 6 -32 10 -38 10z"/>
<path d="M976 2520 c-19 0 -32 -10 -53 -42 -20 -32 -28 -60 -31 -105 -3 -41 1
-78 13 -112 9 -28 20 -51 23 -51 4 0 15 7 25 14 9 7 17 17 17 21 0 5 -10 19
-22 33 -17 18 -23 36 -23 71 0 26 6 55 14 64 7 10 24 17 37 17 13 0 32 -9 42
-20 9 -11 22 -42 28 -68 l10 -47 18 33 c13 25 16 45 10 75 -4 29 -18 53 -44
79 -24 25 -47 38 -64 38z"/>
<path d="M1473 2050 c-5 0 -28 -9 -52 -20 -24 -11 -71 -40 -105 -64 -34 -23
-76 -48 -95 -54 -19 -7 -52 -12 -74 -12 -23 0 -60 9 -84 21 -24 11 -61 42 -83
67 -33 39 -42 44 -50 32 -5 -8 -10 -35 -10 -61 0 -37 -11 -65 -64 -158 -51
-88 -67 -127 -77 -184 -9 -53 -30 -104 -75 -192 -35 -66 -75 -156 -90 -200
-21 -62 -28 -106 -32 -196 l-5 -116 84 -70 c46 -39 120 -100 164 -135 43 -35
90 -78 102 -97 13 -19 23 -46 23 -61 0 -15 -10 -35 -22 -47 -13 -11 -36 -25
-53 -30 -16 -5 -30 -15 -30 -21 0 -5 15 -31 32 -56 18 -25 47 -55 64 -65 17
-11 61 -25 96 -31 39 -8 96 -10 142 -7 42 4 103 13 135 22 33 9 93 35 134 58
41 23 108 74 148 112 l74 70 0 151 c0 134 2 153 18 167 12 11 36 17 65 17 46
0 46 0 58 43 8 28 10 93 6 192 -4 109 -11 170 -27 223 -11 41 -32 97 -46 125
-15 29 -42 71 -61 95 -25 31 -40 64 -54 123 -11 45 -44 132 -73 193 -30 61
-59 123 -65 139 -6 15 -14 27 -18 27z"/>
</g>
</svg>

Can Imagick not open SVG files? It seemed to be doing great with EPS files though. Any help is much appreciated.

cweiske
  • 30,033
  • 14
  • 133
  • 194
Brian Leishman
  • 8,155
  • 11
  • 57
  • 93
  • The error isn't "I don't know what SVG is." The error is "That file does not exist." – kainaw May 01 '15 at 14:36
  • The file does exist, and the path is correct, because I can open it with a file_get_contents(). If I do it that way and open it with `$Vector->readimageblob(file_get_contents($path_to_image));` I get the error `Uncaught exception 'ImagickException' with message 'no decode delegate for this image format` – Brian Leishman May 01 '15 at 14:39
  • 1
    And if you actually read the error, it's saying that the tmp file that Imagick is creating in the background doesn't exist, which is entirely different than my SVG file not existing – Brian Leishman May 01 '15 at 14:40
  • This is likely to be a permissions issue. Does the file '/tmp/magick-aWsnhHLT' get created? And does your webserver have the permissions to read and write to the tmp directory? – Danack May 01 '15 at 20:00
  • 1
    It's not a permissions problem as the same flow works with no errors when using a jpg/png as the source file. It breaks when the source file is an svg. The solution below worked for me. I had to `apt-get install imagemagick` in addition to the already installed `php7.1-imagick` package. – antriver Mar 15 '17 at 02:49

1 Answers1

20

I know I'm late to the party here, but this error is most likely due to a missing library.

Try installing libmagickcore5-extra or libmagickcore-6.q16-2-extra depending on distribution

Found out via this bug report (though not really a bug): https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=576627

Samuel Borgman
  • 108
  • 1
  • 5
Peter
  • 336
  • 3
  • 5