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.

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题