0

I'm trying to read an image with Imagick, I'm using this code on PHP:

<?php

if(extension_loaded('imagick')) {
    echo "Imagick Loaded <br>";
}
else {
    echo "Imagick Not Loaded <br>";
}  

function scaleImage()
{

    $realpath = "D:\Tentacle1.png";
    $imagick = new \Imagick($realpath);

    var_dump($imagick);
}

scaleImage();



?>

The output is this:

Imagick Loaded 
object(Imagick)#1 (0) { }
  • Basically, it does not read the image, it just loads an empty object.

  • It does not give me any errors or warnings.

  • PHP log doesn't show any errors or warnings either.

  • I have tried reading the file contents with this (https://stackoverflow.com/a/16091295/2724978) - no success

  • This test works: https://stackoverflow.com/a/22438898/2724978

  • Image is on the right path, the file name casing is correct

  • I'm on Windows

  • Tried with another file and different extension (JPG), no success either

  • ImageMagick extension shows normally on php_info():

This is incredibly frustrating, I ran out of options to fix it. Could someone help a brother out?

Community
  • 1
  • 1
sigmaxf
  • 7,998
  • 15
  • 65
  • 125
  • why there is a slash("\") before imagick?? – NID Mar 27 '17 at 04:39
  • @PaulCrovella Thanks man.. this is really new info to me.. – NID Mar 27 '17 at 04:47
  • What do you get if you echo $realpath – Orangepill Mar 27 '17 at 04:53
  • One thing that may be causing an issue is the use of the '\' character in the path name... this is the escape character and as such you should either escape it like D:\\Tentacle1.png or just replace it with '/' – Orangepill Mar 27 '17 at 05:06
  • I tried installing updating PHP to 7 and Installing Imagick. Still no success, If I replace with / or \\ also has no change. – sigmaxf Mar 27 '17 at 05:25
  • I also found that passing an invalid path will raise an error, so the path is valid, the image is there, it's just not reading it. – sigmaxf Mar 27 '17 at 05:30

1 Answers1

0

Ok guys, I knew I'd feel like an idiot, the problem was that I'm outputting

echo "Imagick Loaded <br>"; 

before

header("Content-Type: image/jpg");

So I'd always have a blank file. Gosh.

Aside from that, apparently the imagick object is indeed an array of (0) elements, or whatever is showing this output that was confusing me:

object(Imagick)#1 (0) { }

2 hours later, problem solved.

sigmaxf
  • 7,998
  • 15
  • 65
  • 125