Crop image into circle and add border
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:
- create a circle and fill it with black
- create another circle on it and fill with Your image as You do now
精彩评论