图像在 imagick 中变暗

Image gets darker in imagick

我需要帮助(我的英语不好,请尝试理解我要​​查找的内容)。目前我在一个基于图像转换的项目中工作,我正在使用 imagick 来转换图像。我成功地改变了我的形象。我在我的项目中正在做的是拍照(photo1), placing it to another photo (photo2 {the grey are is transparent}) which create the following effect photo3. Then replaceing it again with photo2 (to create the mask effect which showing the hand), and the result is (photo4)。但问题是,photo4 中的 photo1 区域变暗了。 {请比较 photo3 和 photo4}。谁能帮助我如何在 photo4 中保留 photo1 的原始颜色。这是我的代码:

$image1 = new imagick( public_path("img/testImage2.jpg") );
$image2 = new imagick( public_path("storage/Templates/romantisch copy.png"));
$image3 = new imagick( public_path("storage/Templates/romantisch copy.png") );


//for preserving transparency
$image2->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$image3->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);

//resizing photo1
$image1->resizeImage(468, 729, Imagick::FILTER_LANCZOS, 1);

/* Fill background area with transparent */
$image1->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
// $image2->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$image1->setImageArtifact('compose:args', "1,0,-0.5,0.5");

$image1->setImageMatte(true);
$controlPoints = array(
    0, 0, //initial point (top left)
    0, 0, //targeted point (top left)

    0, $image1->getImageHeight(), //initial point (bottom left)
    0, $image1->getImageHeight(), //targeted point (bottom left)

    $image1->getImageWidth(), 0, //initial point (top right)
    $image1->getImageWidth(), 0, //targeted point (top right)

    $image1->getImageWidth(), $image1->getImageHeight(), //initial point (bottom right)
    $image1->getImageWidth(), $image1->getImageHeight() //targeted point (bottom right)
);

// /* Perform the distortion */
$image1->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);

$image2->compositeImage($image1, Imagick::COMPOSITE_OVER, 720, 368);
$image2->compositeImage($image3, Imagick::COMPOSITE_OVER, 0, 0);

/* Ouput the image */
header("Content-Type: image/png");
$image2->writeImage ("test_0.png");
echo $image2;

找到我的解决方案。改变我的色彩空间解决了这个问题。还是不知道为什么。

$image2->transformImageColorspace(\Imagick::COLORSPACE_XYZ);
$image3->transformImageColorspace(\Imagick::COLORSPACE_XYZ);