Imagick:包括PNG导致显示奇怪的符号

I'm using the following code to display an image which is stored on my webspace:

header('Content-Type: image/png');          

$filePath                       =   JPATH_SITE.'/images/powered_by.png';
$image                          =   new Imagick("{$filePath}[0]"); // [0] means "first page"
$image->setImageFormat('png');
echo $image;            
exit;

This happens in a modal-view of my Joomla-Component. The result is the following:

Modal with symbols

What can I do to display the image I wanted to display?

I believe you have a combination of things going wrong.

i. you have errors disabled, which is not showing the real problem.

ii. you have some whitespace at the beginning or end of a file. This is causing the headers to be sent before the code reaches the header('Content-Type: image/png');.

iii. Because the headers have already been sent (with the default text content type) the browser is interpreting the image data as text, and so rendering it as text.

There's nothing wrong with the code you have posted. What you need to do is find out what is causing the png content type not being sent to the browser - which I strongly suspect is going to be done by turning on the display of errors.