CSS Border on PNG image with transparent parts

前端 未结 4 1832
萌比男神i
萌比男神i 2020-12-08 02:42

Im trying to add a border on a PNG image I have (Example included). The thing is that when I add the border currently it adds it on a box shape around all the image and not

4条回答
  •  长情又很酷
    2020-12-08 03:07

    Came across needing to do this myself - came up with this hack. A series of overlaid images behind my original that were slightly out of step with each other. Context ctx3 is a copy of the original image and this would replicate a white silhouette behind the original several times.

          ctx3.shadowColor = "rgba(255,255,255,1)";
          ctx3.globalCompositeOperation = 'source-over';
          ctx3.shadowOffsetX = 2;
          ctx3.shadowOffsetY = 2;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
          ctx3.shadowOffsetX = -2;
          ctx3.shadowOffsetY = -2;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
          ctx3.shadowOffsetX = -2;
          ctx3.shadowOffsetY = 2;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
          ctx3.shadowOffsetX = 2;
          ctx3.shadowOffsetY = -2;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
          ctx3.shadowOffsetX = 0;
          ctx3.shadowOffsetY = 2;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
          ctx3.shadowOffsetX = 0;
          ctx3.shadowOffsetY = -2;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
          ctx3.shadowOffsetX = 2;
          ctx3.shadowOffsetY = 0;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
          ctx3.shadowOffsetX = -2;
          ctx3.shadowOffsetY = 0;
          ctx3.shadowBlur = 0;
          ctx3.drawImage(YourImageSource,0,0);
    

提交回复
热议问题