PHP GD How to circular crop 3 square images and merge into 1 image maintaining transparency

前端 未结 2 1998
渐次进展
渐次进展 2021-01-14 06:21

I have 2 source images and I want to:

  1. Do a circular crop of each image, with the outside of the circle transparent
  2. Merge/copy all images back onto a
2条回答
  •  走了就别回头了
    2021-01-14 07:21

    you can use ImageArtist which a GD wrapper created for making image manipulation insanely easy with php

    $overlay = new Overlay(720, 480, new Color(34,34,36));
    $w = $overlay->getWidth();
    $h = $overlay->getHeight();
    
    $mi = new CircularShape("./mi.jpg");
    $mi->scale(21);
    $mi->setAxises(60,60);
    $mi->build();
    
    $mali = new CircularShape("./mali.jpg");
    $mali->scale(60);
    $mali->setAxises(140,140);
    $mali->build();
    
    $bach = new CircularShape("./har.jpeg");
    $bach->scale(40);
    $bach->setAxises(80,80);
    $bach->build();
    
    $borderd = new CircularShape(new Overlay($bach->getWidth()+10,$bach->getHeight()+10,new Color(255,255,255)));
    $borderd->build();
    $bach = $borderd->merge($bach,5,5);
    
    $img = $overlay->merge($mi,$w/2 + 60,120);
    $img->merge($mali,170,60);
    $img->merge($bach,$w/2,200);
    
    $img->dump(); //this just for demo, but you can use other methods to save this to disk
    

    at the moment ImageArtist does not support borders but if you be little creative you can use an overlay instead. here is the output of the above code.

提交回复
热议问题