Small example to optimize a gray scanned image:
<?php
$im = new Imagick();
$im->readImage("~/scaninput_300DPI.tiff");
//deskew the image
$im->deskewImage(40);
//Crop to A4 and scanner pageoffset 50
$im->cropImage(2480, 3416, 50, 0);
//Need a Monochrome Image
$im->setImageColorspace(2);
$im->thresholdImage(11000);
//Compressen tiff CCITT Group 4
$im->setImageCompression(Imagick::COMPRESSION_GROUP4);
$im->writeimage("~/monochrome_300DPI.tiff");
//Cleanup
$im->clear();
$im->destroy();
?>