Converting PDF to get a preview image using Imagick showing me the wrong colors

That’s my PHP code

$pdfPath = $_GET['path'];
$imagick = new Imagick();
$imagick->setResolution(30, 30);
$imagick->readImage($pdfPath);
$imagick->setImageFormat('png');
$imagick->setIteratorIndex(0);
header('Content-Type: image/png');
echo $imagick;
$imagick->clear();
$imagick->destroy();

and this is the result:

https://imgur.com/gnTJLEC

top = original

bottom = preview using imagick

I tried searching in StackOverflow and other places but the answers seems to be not PHP related and that’s beyond my knowledge. what should I do?