0

Hi currently I built have function to create a thumbnail from an image and it does so, however I want it to be a circle thumbnail not a rectangle, how can I achieve this without using any external libraries just php built in methods? thank you

 function createThumb( $imagepath, $thumbFile, $thumbWidth )
{
// load image and get image size
  $img = imagecreatefromjpeg( "$imagepath" );
  $width = imagesx( $img );
  $height = imagesy( $img );  
  // calculate thumbnail size
  $new_width = $thumbWidth;
  $new_height = floor( $height * ( $thumbWidth / $width ) );
  // create a new temporary image
  $tmp_img = imagecreatetruecolor( $new_width, $new_height );
  // copy and resize old image into new image
  imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, 
                $new_width, $new_height, $width, $height );
  // save thumbnail into a file in the temp directory below script or somewhere
  imagejpeg( $tmp_img, $thumbFile );
}
Squirtle
  • 159
  • 1
  • 2
  • 15

1 Answers1

0

CSS is a better way to do it actually .

.class-name {
   border-radius : 30px;
}
  • Actually CSS is not the answer for every problem. Somebody might need circular images, i.e. to send them to a mobile app – Yar Mar 06 '16 at 11:14