开发者

Crop image into circle and add border

开发者 https://www.devze.com 2022-12-19 18:44 出处:网络
I\'m trying to crop a circle image and adding a border around it. Below is my code to crop a circle image.

I'm trying to crop a circle image and adding a border around it. Below is my code to crop a circle image.

<?php

$img1 = imagecreateFromjpeg("./a.jpg");
$x=ima开发者_如何学Cgesx($img1)-$width ;
$y=imagesy($img1)-$height;


$img2 = imagecreatetruecolor($x, $y);
$bg = imagecolorallocate($img2, 255, 255, 255);
imagefill($img2, 0, 0, $bg);

$e = imagecolorallocate($img2, 0, 0, 0);

$r = $x <= $y ? $x : $y;
imagefilledellipse($img2, ($x/2), ($y/2), $r, $r, $e); 

imagecolortransparent($img2, $e);

imagecopymerge($img1, $img2, 0, 0, 0, 0, $x, $y, 100);

imagecolortransparent($img1, $bg);

header("Content-type: image/png");
imagepng($img1);

imagedestroy($img2);
imagedestroy($img1);

?>

Any ideas or guide I could add a border around it using PHP GD?


If You managed to do the cropping, then it should be easy.

Just create a black circle and put a 2px smaller circle on it and then fil it with the image (that's what You do, isnt'it? ;) )

EDIT:

To be more precise:

Now You create a circle filled with the image. I suggest to:

  1. create a circle and fill it with black
  2. create another circle on it and fill with Your image as You do now
0

精彩评论

暂无评论...
验证码 换一张
取 消