Sometimes the rectangle images are not enough from the design point view. You can crop images using the masks on Photoshop, GIMP or other graphical manipulation software.
Another way to do it is using PHP’s GD library. Conceptual steps for croping image are as follows:
- Create image from source image.
- Resize it for you needs.
- Create the mask. (in our case it’s ellipsis)
- Merge the mask and image.
Code:
<?php $filename = "sapmle.jpg"; $image_s = imagecreatefromjpeg($filename); $width = imagesx($image_s); $height = imagesy($image_s); // New dimensions $newwidth = 285; $newheight = 232; // Create new image $image = imagecreatetruecolor($newwidth, $newheight); imagealphablending($image,true); imagecopyresampled($image,$image_s,0,0,0,0,$newwidth,$newheight,$width,$height); imagedestroy($image_s); // Create mask $mask = imagecreatetruecolor($width, $height); $mask = imagecreatetruecolor($newwidth, $newheight); $transparent = imagecolorallocate($mask, 255, 0, 0); imagecolortransparent($mask, $transparent); imagefilledellipse($mask, $newwidth/2, $newheight/2, $newwidth, $newheight, $transparent); $red = imagecolorallocate($image, 0, 0, 0); imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight,100); imagecolortransparent($image, $red); imagefill($image,0,0, $red); // output and free memory header('Content-type: image/png'); imagepng($image); imagedestroy($image); imagedestroy($mask); ?>

I am happy to announce about PHP 5.3 release. Some of PHP 5.3 advantages are the followings: