Halftone effect using IMagick API
Posted: 2018-11-19T04:26:37-07:00
I am trying to replicate a color halftone effect using the API.
I'm using this command I found on another post on this forum for reference and trying to translate it to API calls but I am not very familiar with the IM command line and am getting stuck.
So far:
What does "-separate null:" do - from what I understood supplying null: as an output file will junk the results so wouldn't this separate the channels then junk them? but of course it isn't doing that. How does the rest of the command receive the separated channels?
Are these channels split as CMYK or is it RGBK? I'm trying to replicate Photoshop's filter which I think uses CMYK.
And... once this works, how would I proceed to make the dots of varying sizes?
Thank you!
I'm using this command I found on another post on this forum for reference and trying to translate it to API calls but I am not very familiar with the IM command line and am getting stuck.
Code: Select all
convert ~/im/images/logo.gif -set option:distort:viewport '%wx%h+0+0' \
-colorspace CMYK -separate null: \
\( -size 2x2 xc: \( +clone -negate \) \
+append \( +clone -negate \) -append \) \
-virtual-pixel tile -filter gaussian \
\( +clone -distort SRT 60 \) +swap \
\( +clone -distort SRT 30 \) +swap \
\( +clone -distort SRT 45 \) +swap \
\( +clone -distort SRT 0 \) +swap +delete \
-compose Overlay -layers composite \
-set colorspace CMYK -combine -colorspace RGB \
logo_cmyk_halftone_2.png
Code: Select all
$im = new Imagick();
$im->readImage('logo.gif');
$im->setImageArtifact('option:distort:viewport', '%wx%h+0+0');
$im->transformImageColorspace(\Imagick::COLORSPACE_CMYK);
$imx = new Imagick();
$imx->setColorspace(\Imagick::COLORSPACE_CMYK);
$imx->newPseudoImage(2, 2, 'xc:'); //-size 2x2 xc:
$imx->addImage($imx->getImage()); //+clone
$imx->negateImage(false); //-negate
$imx->appendImages(false); //+append
$imx->addImage($imx->getImage()); //+clone
$imx->negateImage(false); //-negate
$imx->appendImages(true); //-append
$imx
$imx->setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_TILE);
$imx->setOption('filter:filter', 'Gaussian');
$imf = new Imagick();
$imf->newImage($im->getImageWidth(), $im->getImageHeight(), 'none');
$imcy = clone $im;
$imcy->separateImageChannel(imagick::CHANNEL_CYAN);
$imf->addImage(clone $imx);
//$imf->setImageExtent($im->getImageWidth(), $im->getImageHeight());
$imf->distortImage(imagick::DISTORTION_SCALEROTATETRANSLATE, array(60), true);
//$imf->compositeImage($imcy, imagick::COMPOSITE_OVERLAY, 0, 0);
$im->nextImage();
$im->separateImageChannel(imagick::CHANNEL_MAGENTA);
$imc = clone $imx;
$imc->setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_TILE);
$imc->distortImage(imagick::DISTORTION_SCALEROTATETRANSLATE, array(30), true);
$imc->compositeImage($im, imagick::COMPOSITE_OVERLAY, 0, 0);
$im->setImage($imc);
$im->nextImage();
$im->separateImageChannel(imagick::CHANNEL_YELLOW);
$imc = clone $imx;
$imc->setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_TILE);
$imc->distortImage(imagick::DISTORTION_SCALEROTATETRANSLATE, array(45), true);
$imc->compositeImage($im, imagick::COMPOSITE_OVERLAY, 0, 0);
$im->setImage($imc);
$im->nextImage();
$im->separateImageChannel(imagick::CHANNEL_BLACK);
$imc = clone $imx;
$imc->setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_TILE);
$imc->distortImage(imagick::DISTORTION_SCALEROTATETRANSLATE, array(0), true);
$imc->compositeImage($im, imagick::COMPOSITE_OVERLAY, 0, 0);
$im->setImage($imc);
$im->setColorspace(\Imagick::COLORSPACE_CMYK);
$im = $im->combineImages(imagick::CHANNEL_CYAN | imagick::CHANNEL_MAGENTA | imagick::CHANNEL_YELLOW | imagick::CHANNEL_BLACK);
$im->transformImageColorspace(Imagick::COLORSPACE_RGB);
$im->setFormat('png32');
echo $im;
Are these channels split as CMYK or is it RGBK? I'm trying to replicate Photoshop's filter which I think uses CMYK.
And... once this works, how would I proceed to make the dots of varying sizes?
Thank you!