How to use Imagick Extension in the Exeoutput for php 2021

Sounds like you have done everything correctly. Make sure you have compiled the DLL into project (Making php imagick extension work - SOLVED - #2 by gdgsupport)

The only other suggestion I have is to create a simple test project not using laravel. What I mean is a simple PHP project using imagick. This way you make it easier to troubleshoot.

Some simple PHP examples:

// Create an Imagick object
$image = new Imagick();

// Create a new image
$image->newImage(650, 400, new ImagickPixel('green'));

// Set the image format
$image->setImageFormat('png');

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

// Display the output image
echo $image;
$imagick = new Imagick("/path/to/image.jpg");
$imagick->resizeImage(800, 600, Imagick::FILTER_LANCZOS, 1);
$imagick->writeImage("/path/to/resized_image.jpg");

If you are advanced PHP user, then this may seem redundant, but I have solved a many exeout issues troubleshooting like this.

Here is a script I threw together that might come in handy on the troubleshoot journey:

// Check if Imagick is installed
if (!extension_loaded('imagick')) {
    echo 'Imagick not installed';
} else {
    echo 'Imagick installed';
}

// Check Imagick version
try {
    $imagick = new Imagick();
    $version = $imagick->getVersion();
    echo 'Imagick version: ' . $version['versionString'];
} catch (Exception $e) {
    echo 'Error occurred: ',  $e->getMessage(), "\n";
}

// Check if a specific method is available
if (method_exists('Imagick', 'resizeImage')) {
    echo 'resizeImage method is available';
} else {
    echo 'resizeImage method is not available';
}

// Check if a specific format is supported
$formats = $imagick->queryFormats();
if (in_array('JPEG', $formats)) {
    echo 'JPEG format is supported';
} else {
    echo 'JPEG format is not supported';
}
2 Likes