I am trying to use ImageMagick class functions in PHP. To get familiar with ImageMagick, I wrote a few lines of code in PHP to display a red square in my browser.
Instead of displaying a red square, I get garbled text. I know ImageMagick is installed because I can use ImageMagick functions to save the red square to a file.
Thanks in advance for any help for this newbie to ImageMagick and StackOverflow!
Here's my PHP code:
$image = new Imagick();
$image->newImage(100, 100, new ImagickPixel('red'));
$image->setImageFormat('png');
$image->writeImage("MyOutput.png");
header('Content-type: image/png');
echo $image; //This causes just raw text to be displayed. :(
echo '<img src=MyOutput.png>'; //Displays a 100x100 red image!
//..So, ImageMagick IS installed.
Here's my full PHP file.
<!DOCTYPE html>
<head>
<title>ImageMagick Test</title>
</head>
<body>
<?php
$image = new Imagick();
$image->newImage(100, 100, new ImagickPixel('red'));
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
?>
</body>
</html>