Ich habe versucht, es zu übersetzen, aber funktioniert nicht, weiß niemand, was das Falsche ist?Wie übersetzt man den ImageMagick Befehl zu Imagick in PHP?
ImageMagick
convert source.jpg \(-size 640x480 xc:white -size 200x200
xc:black -geometry +200+100 -compose over -composite \)
+geometry -alpha off -compose copy_opacity -composite result.png
PHP-Code mit Imagick habe ich versucht, aber hat nicht funktioniert:
//Open your image and get its dimensions
$image = new Imagick('source.png');
$height = $image->getImageHeight();
$width = $image->getImageWidth();
//Create a new transparent image of the same size
$mask = new Imagick();
$mask->newImage($width, $height, new ImagickPixel('white'));
//Draw onto the new image the areas you want to be transparent in the original
$draw = new ImagickDraw();
$draw->setFillColor('black');
$draw->rectangle($x, $y, $x + 200, $y + 200);
$mask->drawImage($draw);
//Composite the images
$image->compositeImage($mask, Imagick::COMPOSITE_COPYOPACITY, 0, 0, Imagick::CHANNEL_ALPHA);
$image->setImageFormat('png');
$image->writeImage("~/images/result.png");
Ursprüngliche Frage:
How to make specified area of an image transparent with Imagick?
Ein weiterer Versuch
$width = 256;
$height = 256;
$x = 50;
$y = 100;
$fooWidth = 100;
$fooHeight = 60;
$image = new Imagick();
$image->newImage($width, $height, new ImagickPixel('yellow'));
//Create a new transparent image of the same size
$mask = new Imagick();
$mask->newImage($width, $height, new ImagickPixel('white'));
$mask->setImageFormat('png');
//Draw onto the new image the areas you want to be transparent in the original
$draw = new ImagickDraw();
$draw->setFillColor('black');
$draw->rectangle($x, $y, $x + $fooWidth, $y + $fooHeight);
$mask->drawImage($draw);
//Composite the images
$image->compositeImage($mask, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$image->setImageFormat('png');
$image->writeImage($path);
COMPOSITE_COPYOPACITY
Aussehen nicht funktioniert:
Unglaublich, es funktioniert, wie kann ich Ihnen danken, dass Sie so viel Zeit nehmen, um mir zu helfen, ich sehr sehr schätzen es :) – Suge
'@ Suge' Froh zu hören, dass es geholfen hat. – fmw42