2013-07-16 34 views
0

嗨,目前我建立了从图像创建缩略图的功能,但是我希望它是一个圆形的缩略图而不是矩形,我怎样才能做到这一点,而不使用任何外部库只是PHP内置的方法?谢谢从PHP中的jpeg创建一个圆形缩略图

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

http://stackoverflow.com/questions/8679238/circular-thumbnail-with-php – DevZer0

+0

试试这个:http://php.net/manual/en/function.imagearc.php – senthilbp

+0

也这样: http://stackoverflow.com/questions/2223437/crop-image-into-circle-and-add-border你真的搜索过任何东西吗? – Jorg

回答

1

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

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

非常感谢很多人! – Squirtle

+0

其实CSS不是每个问题的答案。有人可能需要循环图像,即将它们发送到移动应用程序 – Yar