图像在imagick中变暗 [英] Image gets darker in imagick

查看:104
本文介绍了图像在imagick中变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助(我的英语不好,请尝试了解我要查找的内容).目前,我正在基于图像转换的项目中工作,我正在使用imagick转换图像.我已经成功地改变了我的形象.我在我的项目中正在做的是拍摄一张照片(照片1 ),然后将其放置到另一张照片中(照片2 {灰色是透明的}),会产生以下效果 photo4 ).但是问题是,photo4中的photo1区域变暗了. {请比较photo3和photo4}.谁能帮助我如何将photo1的原始颜色保留在photo4中.这是我的代码:

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;

推荐答案

找到了我的解决方案.更改我的色彩空间解决了这个问题.仍然不知道为什么.

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

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

这篇关于图像在imagick中变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆