Search code examples
phpopensslimagickphp-openssl

Imagick stopped working in xampp


Installed Imagick in Xampp using this link. It was working properly but stopped working all of sudden.

Only thing I did in between, tried to configure gmail stmp setting in zend 3. Though I am not sure but it stopped working after that.

This is the error

Fatal error: Uncaught ImagickException: Imagick::__construct(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\xampp\htdocs\restau\restau\public\image.php:55 Stack trace: #0 C:\xampp\htdocs\restau\restau\public\image.php(55): Imagick->__construct('https://storage...') #1 {main} Next ImagickException: Failed to read the file in C:\xampp\htdocs\restau\restau\public\image.php:55 Stack trace: #0 C:\xampp\htdocs\restau\restau\public\image.php(55): Imagick->__construct('https://storage...') #1 {main} thrown in C:\xampp\htdocs\restau\restau\public\image.php on line 55

line of having error

Edit 1

Followed this link and changed

curl.cainfo ="C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem"

openssl.cafile="C:\xampp\perl\vendor\lib\Mozilla\CA\cacert.pem"

this is the error I am getting now

Fatal error: Uncaught ImagickException: Failed to read the file in C:\xampp\htdocs\restau\restau\public\image.php:55 Stack trace: #0 C:\xampp\htdocs\restau\restau\public\image.php(55): Imagick->__construct('https://storage...') #1 {main} thrown in C:\xampp\htdocs\restau\restau\public\image.php on line 55

Below is the code in which image is not getting loaded, this was working properly until few days ago.

<img src="/image.php?filename=https://storage.googleapis.com/xxxxxx/uploads_56ea606ea4685.jpg&amp;width=380&amp;height=255" alt="">

Thanks in advance!!


Solution

  • This is how I fixed this problem.

    I replaced this part of code

    if(filter_var($imagePath, FILTER_VALIDATE_URL)) {
        $imagick = new Imagick($imagePath);
    } else {
        $imagick = new Imagick(getcwd().$imagePath);
    }
    

    with this

    if(filter_var($imagePath, FILTER_VALIDATE_URL)) {
      $tempFile = 'temp/file-'.uniqid().'.jpg';
      copy($imagePath, $tempFile);
      $imagick = new Imagick(getcwd().'/'.$tempFile);
      unlink(getcwd().'/'.$tempFile);
    } else {
      $imagick = new Imagick(getcwd().$imagePath);
    }