Simple way to crop as circle on your image using php code.
If you have any comments just let me know.

$image_s = imagecreatefromstring(file_get_contents($filename));
$width = imagesx($image_s);
$height = imagesy($image_s);

$newwidth = 285;
$newheight = 285;

$image = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($image, true);
imagecopyresampled($image, $image_s, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

//create masking
$mask = imagecreatetruecolor($newwidth, $newheight);

$transparent = imagecolorallocate($mask, 255, 0, 0);
imagecolortransparent($mask,$transparent);

imagefilledellipse($mask, $newwidth/2, $newheight/2, $newwidth, $newheight, $transparent);

$red = imagecolorallocate($mask, 0, 0, 0);
imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight, 100);
imagecolortransparent($image,$red);
imagefill($image, 0, 0, $red);

//output, save and free memory
header(‘Content-type: image/png’);
imagepng($image);
imagepng($image,’output.png’);
imagedestroy($image);
imagedestroy($mask);

Image Circular Crop using PHP Codehttps://blog.herbydesign.com/wp-content/uploads/2021/09/circle.jpghttps://blog.herbydesign.com/wp-content/uploads/2021/09/circle.jpg Hernan Malubay PHPWeb Development
Simple way to crop as circle on your image using php code. If you have any comments just let me know. $image_s = imagecreatefromstring(file_get_contents($filename)); $width = imagesx($image_s); $height = imagesy($image_s); $newwidth = 285; $newheight = 285; $image = imagecreatetruecolor($newwidth, $newheight); imagealphablending($image, true); imagecopyresampled($image, $image_s, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //create masking $mask = imagecreatetruecolor($newwidth, $newheight); $transparent =...
Simple way to crop as circle on your image using php code. If you have any comments just let me know. <code><!--?php </p> <p>$filename = "images/".$_GET['image'].".jpg";<br ?--> $image_s = imagecreatefromstring(file_get_contents($filename)); $width = imagesx($image_s); $height = imagesy($image_s);</code> $newwidth = 285; $newheight = 285; $image = imagecreatetruecolor($newwidth, $newheight); imagealphablending($image, true); imagecopyresampled($image, $image_s, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //create masking $mask = imagecreatetruecolor($newwidth, $newheight); $transparent = imagecolorallocate($mask, 255, 0, 0); imagecolortransparent($mask,$transparent); imagefilledellipse($mask, $newwidth/2, $newheight/2, $newwidth, $newheight, $transparent); $red = imagecolorallocate($mask, 0, 0, 0); imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight, 100); imagecolortransparent($image,$red); imagefill($image, 0, 0, $red); //output, save and free memory header('Content-type: image/png'); imagepng($image); imagepng($image,'output.png'); imagedestroy($image); imagedestroy($mask);