HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelTutorial Source codeReport an issue
Category
Example

Imagick::setOption

← setIteratorIndex   setProgressMonitor →
Associates one or more options with the wand.
// Example 1
public function renderJPG($extent)
{
    $image_path = $this->setOptionControl->getImagePath();
    $imagick = new \Imagick(realpath($image_path));
    $imagick->setImageFormat('jpg');
    $imagick->setOption('jpeg:extent', $extent);
    header("Content-Type: image/jpeg");
    echo $imagick->getImageBlob();
}
// Example 2
public function renderPNG($format)
{
    $image_path = $this->setOptionControl->getImagePath();
    $imagick = new \Imagick(realpath($image_path));
    $imagick->setImageFormat('png');
    $imagick->setOption('png:format', $format);
    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}
// Example 3
public function renderCustomBitDepthPNG()
{
    $image_path = $this->setOptionControl->getImagePath();
    $imagick = new \Imagick(realpath($image_path));
    $imagick->setImageFormat('png');
    $imagick->setOption('png:bit-depth', '16');
    $imagick->setOption('png:color-type', 6);
    header("Content-Type: image/png");
    $crash = true;
    if ($crash) {
        echo $imagick->getImageBlob();
    } else {
        $tempFilename = tempnam('./', 'imagick');
        $imagick->writeimage(realpath($tempFilename));
        echo file_get_contents($tempFilename);
    }
}
// Example 4
public function renderBlackPoint()
{
    // This
    $image_path = $this->setOptionControl->getImagePath();
    $imagick = new \Imagick();
    $imagick->setOption('black-point-compensation', 0.25 * \Imagick::getQuantum());
    $imagick->readImage(realpath($image_path));
    $imagick->setImageFormat('png');
    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}