2013-07-16 96 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