1

i'm having trouble with the php extention imagick. i seem to have it installed properly because in my phpinfo the extention imagick appears.

the problem is when i try to convert a svg to jpg i get the error:

NoDecodeDelegateForThisImageFormat `' @ error/blob.c/BlobToImage/449

My code is base of this example: Convert SVG image to PNG with PHP

function saveSVGToDriveAsPng($svg, $imagepath)
{
//    header('Content-type: image/jpeg');
    $im = new Imagick();
    try {
        $im->readImageBlob($svg);
    } catch (ImagickException $e) {
        echo $svg;

        echo $e->getMessage();
    }
    /*png settings*/
    $im->setImageFormat("png24");
    header('Content-type: image/png');
    $im->writeImage($imagepath);/*(or .jpg)*/
    $im->clear();
    $im->destroy();

$svg example:

    $svg = '<svg version="1.1" id="Laag_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1493.9 377" style="enable-background:new 0 0 1493.9 377;" xml:space="preserve"><style type="text/css">.st0{fill:black;}</style><path id="Pelsterplaat_met_tekstrand" class="st0" d="M1493.9,334.5c0,23.5-19,42.5-42.5,42.5H42.5C19,377,0,358,0,334.5v-292
    C0,19,19,0,42.5,0h1408.8c23.5,0,42.5,19,42.5,42.5V334.5z M1487.5,44.7c0-23.5-17.7-38.1-41.2-38.1H47.2
    C23.7,6.6,6.4,20.9,6.4,44.4v237.9c0,23.5,19,42.5,42.5,42.5H1445c23.5,0,42.5-19,42.5-42.5V44.7z"></path>
<rect id="PrintAreaBG" x="42.52161654135338" y="328.1251409774436" width="1408.8828947368422" height="45.35639097744361" fill="#cdb27d"></rect>
<svg id="svg-banner">
<text id="text-ontwerp" class="st3 st4 st5" alignment-baseline="middle" text-anchor="middle" y="365" x="730">
<tspan id="text1" xml:space="default" fill="rgb(0, 0, 0)" x="730" text-anchor="middle" style="font-family: arial-rounded-mt; text-transform: none; font-size: 40px;">testzooi</tspan> <tspan id="text2" xml:space="default" fill="rgb(255, 255, 255)" x="" text-anchor="middle" style="text-transform: none; font-size: 40px;">Met heel Veel KAAAAASASSS</tspan>
</text>
</svg>
<svg id="svg-image" x="40" y="331" width="80" height="40" viewBox="0 0 141 99"><svg id="svg" version="1.1" width="141" height="99" xmlns="http://www.w3.org/2000/svg"><path d="M19.971 28.378 C 19.956 28.720,19.929 35.862,19.912 44.250 L 19.881 59.500 27.690 59.779 C 34.205 60.011,36.237 59.679,39.941 57.779 C 46.407 54.462,48.500 51.092,48.500 44.000 C 48.500 33.400,42.835 28.847,28.814 28.177 C 23.966 27.945,19.987 28.035,19.971 28.378 M56.000 44.000 L 56.000 60.000 59.500 60.000 L 63.000 60.000 63.000 48.764 L 63.000 37.528 69.778 48.514 L 76.555 59.500 81.278 59.805 L 86.000 60.110 86.000 44.055 L 86.000 28.000 82.500 28.000 L 79.000 28.000 79.000 39.239 L 79.000 50.479 72.250 39.257 L 65.500 28.036 60.750 28.018 L 56.000 28.000 56.000 44.000 M98.663 43.236 C 94.998 51.672,92.000 58.895,92.000 59.287 C 92.000 59.679,93.598 60.000,95.551 60.000 C 98.664 60.000,99.282 59.568,100.564 56.500 C 102.004 53.054,102.119 53.000,108.000 53.000 C 113.881 53.000,113.996 53.054,115.436 56.500 C 116.760 59.669,117.274 60.000,120.881 60.000 L 124.865 60.000 117.992 44.250 C 111.544 29.474,110.940 28.481,108.222 28.199 C 105.382 27.903,105.194 28.200,98.663 43.236 M38.581 37.316 C 40.709 39.147,41.273 40.511,41.273 43.836 C 41.273 48.878,39.151 51.586,34.100 52.989 C 26.934 54.979,27.000 55.059,27.000 44.500 L 27.000 35.000 31.444 35.000 C 34.649 35.000,36.639 35.646,38.581 37.316 M109.799 42.321 C 111.462 46.920,111.424 47.000,107.580 47.000 L 104.161 47.000 105.732 43.000 C 106.596 40.800,107.595 39.000,107.951 39.000 C 108.307 39.000,109.139 40.494,109.799 42.321 M20.394 69.500 C 21.642 73.487,23.000 74.112,23.000 70.700 C 23.000 69.435,23.540 67.860,24.200 67.200 C 25.034 66.366,25.059 66.000,24.283 66.000 C 23.669 66.000,22.904 66.563,22.583 67.250 C 22.117 68.250,21.883 68.250,21.417 67.250 C 20.139 64.513,19.366 66.215,20.394 69.500 M28.161 68.547 C 26.529 72.127,26.667 73.522,28.500 72.000 C 29.697 71.007,30.303 71.007,31.500 72.000 C 32.465 72.801,33.000 72.861,33.000 72.169 C 33.000 70.564,30.780 66.000,30.000 66.000 C 29.627 66.000,28.799 67.146,28.161 68.547 M35.485 68.048 C 35.127 69.174,35.377 70.749,36.040 71.548 C 37.353 73.131,41.000 73.545,41.000 72.111 C 41.000 71.622,40.213 71.285,39.250 71.361 C 38.160 71.448,37.384 70.682,37.191 69.327 C 36.963 67.727,37.489 67.038,39.191 66.714 C 41.293 66.312,41.259 66.260,38.817 66.136 C 36.921 66.040,35.944 66.600,35.485 68.048 M44.232 69.500 C 44.232 71.700,44.438 72.713,44.689 71.750 C 45.247 69.616,48.000 69.408,48.000 71.500 C 48.000 72.325,48.450 73.000,49.000 73.000 C 49.550 73.000,50.000 71.425,50.000 69.500 C 50.000 67.575,49.550 66.000,49.000 66.000 C 48.450 66.000,48.000 66.675,48.000 67.500 C 48.000 69.592,45.247 69.384,44.689 67.250 C 44.438 66.287,44.232 67.300,44.232 69.500 M52.660 66.769 C 53.298 67.174,54.018 68.855,54.260 70.503 L 54.700 73.500 54.850 70.333 C 54.933 68.592,55.563 66.940,56.250 66.662 C 56.938 66.385,56.150 66.129,54.500 66.094 C 52.850 66.059,52.022 66.363,52.660 66.769 M59.000 69.500 C 59.000 71.425,59.450 73.000,60.000 73.000 C 60.550 73.000,61.000 71.425,61.000 69.500 C 61.000 67.575,60.550 66.000,60.000 66.000 C 59.450 66.000,59.000 67.575,59.000 69.500 M63.000 69.500 C 63.000 73.278,64.966 74.475,65.052 70.750 L 65.105 68.500 66.674 70.750 C 68.907 73.951,70.000 73.540,70.000 69.500 C 70.000 67.575,69.592 66.000,69.094 66.000 C 68.595 66.000,68.423 66.900,68.710 68.000 C 68.998 69.100,68.761 70.000,68.184 70.000 C 67.607 70.000,66.849 69.100,66.500 68.000 C 65.409 64.564,63.000 65.596,63.000 69.500 M72.406 67.152 C 72.015 67.785,72.438 68.847,73.347 69.512 C 75.456 71.054,75.433 71.728,73.250 72.361 C 72.234 72.656,72.544 72.792,73.990 72.685 C 76.751 72.480,78.247 69.000,75.573 69.000 C 73.440 69.000,73.573 67.258,75.750 66.689 C 77.101 66.336,77.001 66.206,75.309 66.116 C 74.104 66.052,72.798 66.518,72.406 67.152 M80.160 69.320 C 80.016 72.746,80.232 73.106,82.250 72.820 C 84.053 72.564,84.534 71.804,84.673 69.000 C 84.836 65.698,84.808 65.665,84.173 68.418 C 83.214 72.573,81.219 72.801,80.728 68.811 C 80.324 65.535,80.318 65.540,80.160 69.320 M88.116 69.750 C 88.180 71.813,88.438 72.713,88.689 71.750 C 89.256 69.583,89.945 69.542,91.439 71.586 C 92.402 72.902,92.616 72.562,92.700 69.586 C 92.790 66.439,92.508 66.000,90.401 66.000 C 88.273 66.000,88.013 66.426,88.116 69.750 M96.543 68.918 C 94.508 72.853,94.592 73.258,97.131 71.758 C 98.833 70.753,99.352 70.751,99.714 71.750 C 99.963 72.438,100.556 73.000,101.031 73.000 C 102.044 73.000,100.206 67.246,98.944 66.465 C 98.472 66.173,97.391 67.277,96.543 68.918 M104.118 69.750 C 104.231 73.329,104.265 73.366,104.870 70.547 L 105.503 67.593 107.275 70.297 C 109.684 73.974,111.000 73.692,111.000 69.500 C 111.000 67.575,110.550 66.000,110.000 66.000 C 109.450 66.000,109.000 67.000,109.000 68.223 L 109.000 70.445 107.443 68.223 C 105.160 64.962,103.984 65.502,104.118 69.750 M113.465 67.057 C 113.106 67.638,113.088 69.213,113.425 70.557 C 113.869 72.326,114.722 73.000,116.519 73.000 C 117.884 73.000,119.000 72.592,119.000 72.094 C 119.000 71.595,118.100 71.423,117.000 71.710 C 115.127 72.200,114.855 71.870,114.600 68.795 C 114.545 68.132,115.625 67.277,117.000 66.895 L 119.500 66.199 116.809 66.100 C 115.329 66.045,113.824 66.476,113.465 67.057 M121.000 69.500 C 121.000 72.680,121.252 72.989,123.750 72.884 C 125.442 72.813,125.827 72.592,124.750 72.311 C 123.787 72.059,123.000 71.469,123.000 71.000 C 123.000 70.531,123.787 69.941,124.750 69.689 C 126.417 69.254,126.417 69.226,124.750 69.116 C 123.787 69.052,123.000 68.583,123.000 68.073 C 123.000 67.564,123.787 66.941,124.750 66.689 C 125.827 66.408,125.442 66.187,123.750 66.116 C 121.252 66.011,121.000 66.320,121.000 69.500 M91.500 68.000 C 91.160 68.550,90.459 69.000,89.941 69.000 C 89.423 69.000,89.000 68.550,89.000 68.000 C 89.000 67.450,89.702 67.000,90.559 67.000 C 91.416 67.000,91.840 67.450,91.500 68.000 " stroke="none" fill="rgb(255, 255, 255)" fill-rule="evenodd"></path></svg></svg>
<svg id="svg-image2" x="1370" y="331" width="80" height="40" viewBox="0 0 141 99"><svg id="svg" version="1.1" width="141" height="99" xmlns="http://www.w3.org/2000/svg"><path d="M19.971 28.378 C 19.956 28.720,19.929 35.862,19.912 44.250 L 19.881 59.500 27.690 59.779 C 34.205 60.011,36.237 59.679,39.941 57.779 C 46.407 54.462,48.500 51.092,48.500 44.000 C 48.500 33.400,42.835 28.847,28.814 28.177 C 23.966 27.945,19.987 28.035,19.971 28.378 M56.000 44.000 L 56.000 60.000 59.500 60.000 L 63.000 60.000 63.000 48.764 L 63.000 37.528 69.778 48.514 L 76.555 59.500 81.278 59.805 L 86.000 60.110 86.000 44.055 L 86.000 28.000 82.500 28.000 L 79.000 28.000 79.000 39.239 L 79.000 50.479 72.250 39.257 L 65.500 28.036 60.750 28.018 L 56.000 28.000 56.000 44.000 M98.663 43.236 C 94.998 51.672,92.000 58.895,92.000 59.287 C 92.000 59.679,93.598 60.000,95.551 60.000 C 98.664 60.000,99.282 59.568,100.564 56.500 C 102.004 53.054,102.119 53.000,108.000 53.000 C 113.881 53.000,113.996 53.054,115.436 56.500 C 116.760 59.669,117.274 60.000,120.881 60.000 L 124.865 60.000 117.992 44.250 C 111.544 29.474,110.940 28.481,108.222 28.199 C 105.382 27.903,105.194 28.200,98.663 43.236 M38.581 37.316 C 40.709 39.147,41.273 40.511,41.273 43.836 C 41.273 48.878,39.151 51.586,34.100 52.989 C 26.934 54.979,27.000 55.059,27.000 44.500 L 27.000 35.000 31.444 35.000 C 34.649 35.000,36.639 35.646,38.581 37.316 M109.799 42.321 C 111.462 46.920,111.424 47.000,107.580 47.000 L 104.161 47.000 105.732 43.000 C 106.596 40.800,107.595 39.000,107.951 39.000 C 108.307 39.000,109.139 40.494,109.799 42.321 M20.394 69.500 C 21.642 73.487,23.000 74.112,23.000 70.700 C 23.000 69.435,23.540 67.860,24.200 67.200 C 25.034 66.366,25.059 66.000,24.283 66.000 C 23.669 66.000,22.904 66.563,22.583 67.250 C 22.117 68.250,21.883 68.250,21.417 67.250 C 20.139 64.513,19.366 66.215,20.394 69.500 M28.161 68.547 C 26.529 72.127,26.667 73.522,28.500 72.000 C 29.697 71.007,30.303 71.007,31.500 72.000 C 32.465 72.801,33.000 72.861,33.000 72.169 C 33.000 70.564,30.780 66.000,30.000 66.000 C 29.627 66.000,28.799 67.146,28.161 68.547 M35.485 68.048 C 35.127 69.174,35.377 70.749,36.040 71.548 C 37.353 73.131,41.000 73.545,41.000 72.111 C 41.000 71.622,40.213 71.285,39.250 71.361 C 38.160 71.448,37.384 70.682,37.191 69.327 C 36.963 67.727,37.489 67.038,39.191 66.714 C 41.293 66.312,41.259 66.260,38.817 66.136 C 36.921 66.040,35.944 66.600,35.485 68.048 M44.232 69.500 C 44.232 71.700,44.438 72.713,44.689 71.750 C 45.247 69.616,48.000 69.408,48.000 71.500 C 48.000 72.325,48.450 73.000,49.000 73.000 C 49.550 73.000,50.000 71.425,50.000 69.500 C 50.000 67.575,49.550 66.000,49.000 66.000 C 48.450 66.000,48.000 66.675,48.000 67.500 C 48.000 69.592,45.247 69.384,44.689 67.250 C 44.438 66.287,44.232 67.300,44.232 69.500 M52.660 66.769 C 53.298 67.174,54.018 68.855,54.260 70.503 L 54.700 73.500 54.850 70.333 C 54.933 68.592,55.563 66.940,56.250 66.662 C 56.938 66.385,56.150 66.129,54.500 66.094 C 52.850 66.059,52.022 66.363,52.660 66.769 M59.000 69.500 C 59.000 71.425,59.450 73.000,60.000 73.000 C 60.550 73.000,61.000 71.425,61.000 69.500 C 61.000 67.575,60.550 66.000,60.000 66.000 C 59.450 66.000,59.000 67.575,59.000 69.500 M63.000 69.500 C 63.000 73.278,64.966 74.475,65.052 70.750 L 65.105 68.500 66.674 70.750 C 68.907 73.951,70.000 73.540,70.000 69.500 C 70.000 67.575,69.592 66.000,69.094 66.000 C 68.595 66.000,68.423 66.900,68.710 68.000 C 68.998 69.100,68.761 70.000,68.184 70.000 C 67.607 70.000,66.849 69.100,66.500 68.000 C 65.409 64.564,63.000 65.596,63.000 69.500 M72.406 67.152 C 72.015 67.785,72.438 68.847,73.347 69.512 C 75.456 71.054,75.433 71.728,73.250 72.361 C 72.234 72.656,72.544 72.792,73.990 72.685 C 76.751 72.480,78.247 69.000,75.573 69.000 C 73.440 69.000,73.573 67.258,75.750 66.689 C 77.101 66.336,77.001 66.206,75.309 66.116 C 74.104 66.052,72.798 66.518,72.406 67.152 M80.160 69.320 C 80.016 72.746,80.232 73.106,82.250 72.820 C 84.053 72.564,84.534 71.804,84.673 69.000 C 84.836 65.698,84.808 65.665,84.173 68.418 C 83.214 72.573,81.219 72.801,80.728 68.811 C 80.324 65.535,80.318 65.540,80.160 69.320 M88.116 69.750 C 88.180 71.813,88.438 72.713,88.689 71.750 C 89.256 69.583,89.945 69.542,91.439 71.586 C 92.402 72.902,92.616 72.562,92.700 69.586 C 92.790 66.439,92.508 66.000,90.401 66.000 C 88.273 66.000,88.013 66.426,88.116 69.750 M96.543 68.918 C 94.508 72.853,94.592 73.258,97.131 71.758 C 98.833 70.753,99.352 70.751,99.714 71.750 C 99.963 72.438,100.556 73.000,101.031 73.000 C 102.044 73.000,100.206 67.246,98.944 66.465 C 98.472 66.173,97.391 67.277,96.543 68.918 M104.118 69.750 C 104.231 73.329,104.265 73.366,104.870 70.547 L 105.503 67.593 107.275 70.297 C 109.684 73.974,111.000 73.692,111.000 69.500 C 111.000 67.575,110.550 66.000,110.000 66.000 C 109.450 66.000,109.000 67.000,109.000 68.223 L 109.000 70.445 107.443 68.223 C 105.160 64.962,103.984 65.502,104.118 69.750 M113.465 67.057 C 113.106 67.638,113.088 69.213,113.425 70.557 C 113.869 72.326,114.722 73.000,116.519 73.000 C 117.884 73.000,119.000 72.592,119.000 72.094 C 119.000 71.595,118.100 71.423,117.000 71.710 C 115.127 72.200,114.855 71.870,114.600 68.795 C 114.545 68.132,115.625 67.277,117.000 66.895 L 119.500 66.199 116.809 66.100 C 115.329 66.045,113.824 66.476,113.465 67.057 M121.000 69.500 C 121.000 72.680,121.252 72.989,123.750 72.884 C 125.442 72.813,125.827 72.592,124.750 72.311 C 123.787 72.059,123.000 71.469,123.000 71.000 C 123.000 70.531,123.787 69.941,124.750 69.689 C 126.417 69.254,126.417 69.226,124.750 69.116 C 123.787 69.052,123.000 68.583,123.000 68.073 C 123.000 67.564,123.787 66.941,124.750 66.689 C 125.827 66.408,125.442 66.187,123.750 66.116 C 121.252 66.011,121.000 66.320,121.000 69.500 M91.500 68.000 C 91.160 68.550,90.459 69.000,89.941 69.000 C 89.423 69.000,89.000 68.550,89.000 68.000 C 89.000 67.450,89.702 67.000,90.559 67.000 C 91.416 67.000,91.840 67.450,91.500 68.000 " stroke="none" fill="rgb(255, 255, 255)" fill-rule="evenodd"></path></svg></svg>
</svg>';

I expect this code write a image to my server based on the svg. currently after hours of trial and error i still get the error stated above.

Bart
  • 11
  • 3
  • I am not an expert on Imagick. But SVG probably should be read as an image not a blob. Blobs are for base64 data. Imagemagick knows to use SVG renderers to process SVG files. So try reading it as a normal image. – fmw42 May 14 '19 at 16:42
  • @fmw42 readImageFromBlob is the correct method here. The 'fromBlob' indicates the string is a blob of data, to separate it it from readImage, which takes a string filename. https://phpimagick.com/Imagick/readImageBlob – Danack May 14 '19 at 17:36
  • @bart The error message is saying you don't have the appropriate software on your machine to read that image. Can you try from the command line just using ImageMagick's 'convert' command. You don't say which OS you're usin. – Danack May 14 '19 at 17:38
  • `@Danack` Thanks for the information. I only know the command line. So I appreciate your correction. – fmw42 May 14 '19 at 17:54
  • @Danack if i run imagick convert in the command line everything works. i'm using win 10 – Bart May 16 '19 at 07:20
  • The error was most likely to be a faulty installation of imagick. My fix was to build this feature on a staging site of the live site – Bart Jul 03 '19 at 14:59

1 Answers1

0

The problem lied in having a faulty installation of imagick. once i ran this on a live site, it worked.

Bart
  • 11
  • 3