将 Imagemagick 命令转换为 php imagick
Convert Imagemagick command to php imagick
我需要将 ImageMagick 命令转换为 PHP Imagick。我尝试了几种组合,但没有达到预期效果。该命令创建一条具有尖边和边缘渐变的线
命令是:
convert -size 300x1 xc:red \
\( -size 1x300 gradient: -rotate 90 -solarize 50% -level 0x50% -white-threshold 50% +write grad.png \) \
-alpha off -compose copy_opacity -composite red_grad.png`
感谢@fmw42 提供此命令
我试过以下代码:
$line = new Imagick();
$line->newPseudoImage(300,1,'xc:red');
$shadow = new Imagick();
$shadow->newPseudoImage(1, 300, 'gradient:red-white');
$shadow->rotateImage('transparent', 90);
$shadow->solarizeImage(50);
$shadow->levelImage(0,50,50);
$shadow->whiteThresholdImage('white');
$shadow->setImageCompose(0);
$shadow->writeImage('grad.png');
$shadow->compositeImage($line, Imagick::COMPOSITE_MATHEMATICS, 0, 0);
请指出我错在哪里
我对翻译的最佳猜测如下。但是,这是未经测试的,我不太了解 Imagick。
$redline = new Imagick();
$redline->newPseudoImage(300,1,'xc:red');
$grad = new Imagick();
$grad->newPseudoImage(1, 300, 'gradient:black-white');
$grad->rotateImage('white', 90);
$grad->solarizeImage(50*Imagick::getQuantumRange/100);
$grad->levelImage(0,1,50*Imagick::getQuantumRange/100);
$grad->whiteThresholdImage(50*Imagick::getQuantumRange/100);
$redline->compositeImage($grad, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$redline->writeImage("redline.png");
通过一些调整,@fmw42 的回答对我有用。正确解法如下
$redline = new Imagick();
$redline->newPseudoImage(1100,3,'xc:'.$chipColourPixel->getColorAsString());
$grad = new Imagick();
$grad->newPseudoImage(3, 900, 'gradient:black-white');
$grad->rotateImage('white', 90);
$grad->solarizeImage((int)ceil(50*Imagick::QUANTUM_RANGE/100));
$grad->levelImage(0,1,50*Imagick::QUANTUM_RANGE/100);
$redline->compositeImage($grad, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$redline->writeImage("redline.png");
我需要将 ImageMagick 命令转换为 PHP Imagick。我尝试了几种组合,但没有达到预期效果。该命令创建一条具有尖边和边缘渐变的线 命令是:
convert -size 300x1 xc:red \
\( -size 1x300 gradient: -rotate 90 -solarize 50% -level 0x50% -white-threshold 50% +write grad.png \) \
-alpha off -compose copy_opacity -composite red_grad.png`
感谢@fmw42 提供此命令
我试过以下代码:
$line = new Imagick();
$line->newPseudoImage(300,1,'xc:red');
$shadow = new Imagick();
$shadow->newPseudoImage(1, 300, 'gradient:red-white');
$shadow->rotateImage('transparent', 90);
$shadow->solarizeImage(50);
$shadow->levelImage(0,50,50);
$shadow->whiteThresholdImage('white');
$shadow->setImageCompose(0);
$shadow->writeImage('grad.png');
$shadow->compositeImage($line, Imagick::COMPOSITE_MATHEMATICS, 0, 0);
请指出我错在哪里
我对翻译的最佳猜测如下。但是,这是未经测试的,我不太了解 Imagick。
$redline = new Imagick();
$redline->newPseudoImage(300,1,'xc:red');
$grad = new Imagick();
$grad->newPseudoImage(1, 300, 'gradient:black-white');
$grad->rotateImage('white', 90);
$grad->solarizeImage(50*Imagick::getQuantumRange/100);
$grad->levelImage(0,1,50*Imagick::getQuantumRange/100);
$grad->whiteThresholdImage(50*Imagick::getQuantumRange/100);
$redline->compositeImage($grad, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$redline->writeImage("redline.png");
通过一些调整,@fmw42 的回答对我有用。正确解法如下
$redline = new Imagick();
$redline->newPseudoImage(1100,3,'xc:'.$chipColourPixel->getColorAsString());
$grad = new Imagick();
$grad->newPseudoImage(3, 900, 'gradient:black-white');
$grad->rotateImage('white', 90);
$grad->solarizeImage((int)ceil(50*Imagick::QUANTUM_RANGE/100));
$grad->levelImage(0,1,50*Imagick::QUANTUM_RANGE/100);
$redline->compositeImage($grad, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$redline->writeImage("redline.png");