drbfxb977777 2014-06-12 12:19
浏览 94

too long

I'm new to imagemagic aka imagick on php and im trying to follow this thread using php code. I have tried to apply this logo onto a tshirt but couldn't do so by following the threas becuase i cannot find most of the methods in php like using displacement map to start with. What i have tried is the following code:

$image = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/images/VYLZsoD.jpg');    
$logo = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/images/logo.png');
$logo->resizeImage(200, 200, imagick::FILTER_LANCZOS, 1, TRUE);    
header("Content-Type: image/jpg");

$image->compositeimage($logo, Imagick::COMPOSITE_DEFAULT, 400, 260); 
$image->flattenImages();

echo $image;

I would want to use the steps shown in the thread to create a mask and so on in order to apply the logo onto the tshirt using php code (not via command). I have even used "COMPOSITE_OVERLAY" to make the logo look like its part of the tshirt but it seems like the original color of the logo reduces because of the transparency, check here for my final tshirt http://i62.tinypic.com/2ahuw6h.png.

  1. Please tell me how i can archive a better result using imagick in php (without the color of the logo is being reduced)
  2. Can i mark a territory on the tshirt so that when i drag the logo around, it wouldn't show outside the tshirt border?

Source tshirt http://i58.tinypic.com/154j52b.jpg Source logo http://i59.tinypic.com/e02051.png

  • 写回答

4条回答

  • douzhu6149 2014-06-13 12:04
    关注

    The output image you posted doesn't look like the output image I see when running your code. Obviously adjusting the position a little, the output image I see doesn't have the color reduced.

    enter image description here

    If you don't see see the same thing, it may be a bug in your version of ImageMagick. You could try using the composite method COMPOSITE_ATOP, which should produce the same result, via a different blend method.

    For your second question, how to limit the logo overlay to the edge of the Tshirt, you can do it by creating a mask out of the tshirt, painting the logo onto that mask with COMPOSITE_SRCIN and then painting the result of that onto the tshirt:

        $tshirt = new \Imagick(realpath("../images/tshirt/tshirt.jpg"));
        $logo = new \Imagick(realpath("../images/tshirt/Logo.png"));
        $logo->resizeImage(100, 100, \Imagick::FILTER_LANCZOS, 1, TRUE);
    
        $tshirt->setImageFormat('png');
    
        $max = $image->getQuantumRange();
        $max = $max["quantumRangeLong"];
    
        //Create a mask by cloning the shirt,
        $mask = clone $tshirt;
        //Negating the image,
        $mask->negateimage(true);
        //Make it transparent everywhere that it is now white.
        $mask->transparentPaintImage(
            'black', 
            0, 
            0.1 * $max, 
            false
        );
    
        //Paint the logo onto the mask, SRCIN just uses the logo's color
        $mask->compositeimage($logo, \Imagick::COMPOSITE_SRCIN, 210, 75);
        //Paint the result of the logo + mask onto the tshirt.
        $tshirt->compositeimage($mask, \Imagick::COMPOSITE_DEFAULT, 0, 0);
        //Merge the image with a non-deprecated function.
        $tshirt->mergeimagelayers(\Imagick::LAYERMETHOD_COALESCE);
    
        header("Content-Type: image/png");
        echo $tshirt->getImageBlob();
    }
    

    Which produces something like:

    enter image description here

    Whether that's a good idea or not is another matter.

    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗