Image gets darker in imagick

≯℡__Kan透↙ 提交于 2019-12-24 17:00:22

问题


I need help (My english is not good, please try to understand what i'm trying to find). Currently i'm working in a project based on image transformation, where i'm using imagick to transform image. I'm successfully transformed my image. What i am doing in my project is taking a photo(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). But the problem is, photo1 area in photo4 gets darker. {Please compare photo3 and photo4}. Can anyone help me how to keep the original color of photo1 in photo4. Here is my code:

$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;

回答1:


Found my solution. Changing my colorspace solved the problem. still don't know why.

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


来源:https://stackoverflow.com/questions/51402288/image-gets-darker-in-imagick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!