在PHP中从jpeg创建一个圆形缩略图



Hi目前我构建了一个从图像创建缩略图的功能,它确实做到了,但我希望它是圆形缩略图,而不是矩形,如果不使用任何外部库(仅php内置方法),我如何实现这一点?谢谢

 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 );
}

CSS实际上是一种更好的方法。

.class-name {
   border-radius : 30px;
}

最新更新