You can crop the image using intervention then use CSS to make the cropped image circular.
.image {
border-radius: 50%:
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I would like to know if anyone has ever done this or if anyone knows how to do it.
Thanks in advance!
You can crop the image using intervention then use CSS to make the cropped image circular.
.image {
border-radius: 50%:
}
@mezie Thanks for your answer, but I need to crop it as circle, without using CSS.
Hello there, you can use this package http://image.intervention.io/api/circle
btw, It is giving me troubles with an empty content, but I am working on it.
Hope it works out for you
@gocanto I'm trying to get it done with that package too, but seems like is not posible.
I also found this: http://stackoverflow.com/questions/30094341/php-gd-how-to-circular-crop-3-square-images-and-merge-into-1-image-maintaining-t and the following function works great:
function create_circle( $img_path ) {
// Attribution: by NerdsOfTech
// Step 1 - Start with image as layer 1 (canvas).
if (! $img1 = $this->imageCreateFromAny( $img_path )) {
return FALSE;
}
$x=imagesx($img1);
$y=imagesy($img1);
// Step 2 - Create a blank image.
$img2 = imagecreatetruecolor($x, $y);
$bg = imagecolorallocate($img2, 255,0,255, 127); // wierdo pink background
// $bg = imagecolorallocate($img2, 0, 0, 0, 127 ); // white background
imagefill($img2, 0, 0, $bg);
imagecolortransparent($img2, $bg);
// Step 3 - Create the ellipse OR circle mask.
$e = imagecolorallocate($img2, 255, 255, 255); // black mask color
// Draw a ellipse mask
imagefilledellipse ($img2, ($x/2), ($y/2), $x, $y, $e);
// OR
// Draw a circle mask
// $r = $x <= $y ? $x : $y; // use smallest side as radius & center shape
// imagefilledellipse ($img2, ($x/2), ($y/2), $r, $r, $e);
// Step 4 - Make shape color transparent
imagecolortransparent($img2, $e);
// Step 5 - Merge the mask into canvas with 100 percent opacity
imagecopymerge($img1, $img2, 0, 0, 0, 0, $x, $y, 100);
// Step 6 - Make outside border color around circle transparent
imagecolortransparent($img1, $bg);
/* Clean up memory */
imagedestroy($img2);
return $img1;
}
But still trying to make it work with Image Intervention.
The package works fine my friend. I just tested the example in an online server and it works smoothly.
So, if your example is not working out, trying seeing the php "memory_limit" value. Look at their recommendations
http://image.intervention.io/getting_started/configuration
Let me know if you need me for something else!
@gocanto I know the package works frin, its just that the functions it has are not enough to acomplish what I need.
Wow this is old but I know what you want and in my opinion the code you posted is too complex...
You can do this in intervention image by masking the image with a circle shape:
Route::get('circle_image.png', function () {
# Create you image
$img = Image::make(storage_path('app/public/image.jpg'));
// Apply a smart crop
$img->fit(1000);
// create empty canvas with transparent background
$canvas = Image::canvas(1000, 1000);
// draw a black circle on it
$canvas->circle(1000, 500, 500, function ($draw) {
$draw->background('#000000');
});
// Mask your image with the shape
$img->mask($canvas->encode('png', 75), true);
// Response with the image or you can as well do whatever you like with it.
return $img->response('png');
});
This should work well if you have the GD extention installed.
Please or to participate in this conversation.