38

Any ideas how to fix this ?

 ImagickException: not authorized `/tmp/magick-1552lvf2nIjaqx1W' @ error/constitute.c/ReadImage/412 

I thought it was a permission issue so just to test it out i set my /tmp dir to 777. No change. Its driving me crazy.

The command :

<?php


$image = new \Imagick();
$image->readImageBlob('<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $graph);
7
  • How about telling us what command caused this? Jun 2, 2016 at 18:53
  • Pasting your command may give an insight - have you been able to get Imagick to work at all? Depending on your server the CHMOD could be 755
    – Bonzo
    Jun 2, 2016 at 18:53
  • Have you tried setting and exporting the environment variable MAGICK_TMPDIR to someplace else where your script/CGI/program can write? Jun 2, 2016 at 18:55
  • It might be your policy.xml having something in the <policymap> that [accidentally?] includes that file type as a matched pattern.
    – kb.
    Jun 2, 2016 at 19:02
  • I tried 775 ,and changing the location: still having issues.
    – LukePOLO
    Jun 2, 2016 at 19:04

4 Answers 4

70

I have followed the below Steps to fix the Fatal error:

Uncaught ImagickException: not authorized `../../c02_001.pdf'
@ error/constitute.c/ReadImage/412 

  1. sudo vi policy.xml from etc/Imagemagick-6/
  2. comment the following line

    <!-- <policy domain="coder" rights="none" pattern="MVG" /> -->
    
  3. Rewrite the following line

    <policy domain="coder" rights="none" pattern="PDF" />
    

    to

    <policy domain="coder" rights="read|write" pattern="PDF" />
    
  4. sudo apt-get install inkscape

  5. Restart apache with following command sudo restart apache2
5
  • 8
    <policy domain="coder" rights="read|write" pattern="PDF" /> this worked for me.
    – Chinmoy
    Oct 8, 2018 at 4:38
  • 11
    If you're using php-fpm, use sudo service php7.2-fpm restart (or your version of PHP) instead of restarting apache. Oct 17, 2018 at 20:54
  • thank you. I did use vim for this change. Not nano obviously! #realCoder Nov 28, 2018 at 7:18
  • why step 4 sudo apt-get install inkscape? Everything works without it. Thanks, you saved my day too!
    – cronfy
    Feb 10, 2021 at 8:40
  • 5. sudo service apache2 restart
    – Jimit Shah
    Jun 19, 2021 at 7:23
27

Your policy "MVG" could be the reason. Just comment

<policy domain="coder" rights="none" pattern="MVG" />

in /etc/ImageMagick/policy.xml and restart Apache server.

4
  • Thank you for this answer! I install stuff with brew. my etc with /ImageMagick/policy.xml was in usr/local/ - just if someone else end up here with my setup Sep 14, 2018 at 10:25
  • 6
    you can run locate policy.xm to find the file in case the location differs. Then do the replace: sudo sed -i -e 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml, see stackoverflow.com/a/52677573/367456 below as well.
    – hakre
    Oct 17, 2018 at 13:58
  • And what about NGINX ?
    – KSPR
    May 22, 2019 at 8:15
  • @kspr - for nginx you would restart php-fpm - with apache the php runtime is loaded as a module, for nginx (and other web servers) it's the seperate fastcgi version of php
    – DorianFM
    Feb 3, 2021 at 11:48
1

i hope this solution will help you I'm facing the same issue and I'm on the live server i'm trying to follow above Mikel Annjuk and hakre answer so i cannot the change the file /etc/ImageMagick/policy.xml so i contact to the server provider to edit file and send this url to follow step but there is answering me

" I am still working on this. The solution given in above link requires root access to the server which is not possible in a shared server. But imagick is related to php. So let me try changing php version and see if that helps"

when i tired to resolve this on that time i have idea may be the issue of the file path where I'm saving the file so I change to base path to FCPATH and the matter is solved. i'm using Codeigniter base_url() to php FCPATH this is the point to solve this issue

but on svg converter show "no decode delegate" issue

add the following lines in the start of file or code

like this

$usmap = file_get_contents(base_url('convert/plus.svg')); 
     $find_string   = '<svg';
$position = strpos($usmap, $find_string);

   $svg_file_new ='<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.substr($usmap, $position).'</svg>';
       file_put_contents(FCPATH.'convert/plus.svg', $svg_file_new);

        $usmap = base_url('convert/plus.svg'); 
$im = new Imagick($usmap);  
$im->setImageFormat("jpg"); 

$im->writeImage(FCPATH .'convert/plus.jpg');
$im->clear();
$im->destroy();

above code first, get the SVG code from the file and add XML version code then put it into the file and then convert SVG to any type of image like jpg

sorry for my English

4
  • I am not sure XML/SVG files should be read as blobs. Try reading as a normal image.
    – fmw42
    May 31, 2019 at 23:24
  • just simple code $pdfPath = base_url('convert/ResumeAnusShahbaz0.jpeg'); $im = new imagick($pdfPath); $im->setImageFormat('pdf'); $im->writeImage(FCPATH .'convert/ResumeAnusShahbaz0.pdf'); $im->clear(); $im->destroy(); May 31, 2019 at 23:33
  • it work on many image format still i'm find one issue svg to other above 12 i have checked its work and another format i'm trying to convert lest how many format work on this code May 31, 2019 at 23:36
  • i have the solution for svg converter update my answer Jun 1, 2019 at 1:15
0

An "strace" of the PHP process shown the following:

sh: inkscape: command not found

I fixed this by:

apt-get install inkscape

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.