function levelImageColors( string $image_path, $black_color, $white_color, bool $invert ) { $imagick = new \Imagick(realpath($image_path)); $imagick->setFormat('png'); $imagick->levelImageColors( $black_color, $white_color, $invert ); header("Content-Type: image/png"); echo $imagick->getImageBlob(); }