Cut any shape from image ( Imagik/Gd)

こ雲淡風輕ζ 提交于 2019-12-22 09:55:37

问题


Is there any way to cut any shape from square image in PHP ?

Example, I have image with heart shape:

Another image in same size like heart.

Final image:

So my question is there way in PHP to make such effect from two images, or one image ?


回答1:


You basically just want to copy the opacity of the heart template into the car picture. So, at the command-line, you would do:

convert motor.jpg heart.png -compose copyopacity -composite result.png

And in PHP:

#!/usr/local/bin/php -f
<?php
   $template=new Imagick('heart.png');
   $image   =new Imagick('motor.jpg');

   # Copy alpha from template over car image
   $image->compositeImage($template,imagick::COMPOSITE_COPYOPACITY,0,0);
   $image->writeImage('result.png');
?>


来源:https://stackoverflow.com/questions/36823319/cut-any-shape-from-image-imagik-gd

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