Rounded transparent _smooth_ corners using imagecopyresampled() PHP GD

后端 未结 3 529
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 06:14

I need a script which makes rounded transparent corners on supplied image. I\'ve found one and it works good except the one thing: the applied corners do not look smooth. Th

3条回答
  •  我在风中等你
    2020-12-09 06:28

    ...
    
    /* rounded corner */
    $radius = 20;
    
    // find ghost color
    do
    {
      $r = rand(0, 255);
      $g = rand(0, 255);
      $b = rand(0, 255);
    } while (imagecolorexact($img_resource, $r, $g, $b) < 0);
    $ghost_color = imagecolorallocate($img_resource, $r, $g, $b);
    
    imagearc($img_resource, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $ghost_color);
    imagefilltoborder($img_resource, 0, 0, $ghost_color, $ghost_color);
    imagearc($img_resource, $img_width-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $ghost_color);
    imagefilltoborder($img_resource, $img_width-1, 0, $ghost_color, $ghost_color);
    imagearc($img_resource, $radius-1, $img_height-$radius, $radius*2, $radius*2, 90, 180, $ghost_color);
    imagefilltoborder($img_resource, 0, $img_height-1, $ghost_color, $ghost_color);
    imagearc($img_resource, $img_width-$radius, $img_height-$radius, $radius*2, $radius*2, 0, 90, $ghost_color);
    imagefilltoborder($img_resource, $img_width-1, $img_height-1, $ghost_color, $ghost_color);
    
    imagecolortransparent($img_resource, $ghost_color);
    
    ...
    

    try this one ...

提交回复
热议问题