2012-08-14 75 views
1

func.php文件,當圖像上傳到網站時,它生成縮略圖。我明白如何通過5半徑圓潤的邊角,但由於某種原因,我很爲難,現在在哪裏納入圓角到我的代碼,請大家幫忙:如何使用php和html在縮略圖上創建圓角?

<?php 
function create_thumb($directory, $image, $destination) { 
    $image_file = $image; 
    $image = $directory.$image; 

if (file_exists($image)) { 

$source_size = getimagesize($image); 

if ($source_size !== false) { 

    $thumb_width = 100; 
    $thumb_height = 100; 

    switch($source_size['mime']) { 
    case 'image/jpeg': 
     $source = imagecreatefromjpeg($image); 
    break; 
    case 'image/png': 
     $source = imagecreatefrompng($image); 
    break; 
    case 'image/gif': 
     $source = imagecreatefromgif($image); 
    break; 
    } 

    $source_aspect = round(($source_size[0]/$source_size[1]), 1); 
    $thumb_aspect = round(($thumb_width/$thumb_height), 1); 

    if ($source_aspect < $thumb_aspect) { 
    $new_size = array($thumb_width, ($thumb_width/$source_size[0]) * $source_size[1]); 
    $source_pos = array(0, ($new_size[1] - $thumb_height)/2); 
    } else if ($source_aspect > $thumb_aspect) { 
    $new_size = array(($thumb_width/$source_size[1]) * $source_size[0], $thumb_height); 
    $source_pos = array(($new_size[0] - $thumb_width)/2, 0); 
    } else { 
    $new_size = array($thumb_width, $thumb_height); 
    $source_pos = array(0, 0); 
    } 

    if ($new_size[0] < 1) $new_size[0] = 1; 
    if ($new_size[1] < 1) $new_size[1] = 1; 

    $thumb = imagecreatetruecolor($thumb_width, $thumb_height); 
    imagecopyresampled($thumb, $source, 0, 0, $source_pos[0], $source_pos[1], $new_size[0], $new_size[1], $source_size[0], $source_size[1]); 

    switch($source_size['mime']) { 
    case 'image/jpeg': 
     imagejpeg($thumb, $destination.$image_file); 
    break; 
    case 'image/png': 
      imagepng($thumb, $destination.$image_file); 
    break; 
    case 'image/gif': 
     imagegif($thumb, $destination.$image_file); 
    break; 
    } 


} 

    } 
} 
?> 
+0

你不能只是使用CSS的'邊界radius'?如果你使用http://css3pie.com/它甚至可以在IE6上工作:) – biziclop 2012-08-14 20:01:27

+0

是的CSS是更好更優雅的解決方案。你爲什麼不使用它? – bksi 2012-08-14 20:02:29

+0

這個問題的可能重複http://stackoverflow.com/questions/609109/rounded-corners-on-images-using-php?rq=1 – jco 2012-08-14 20:04:01

回答

2

此代碼看起來像它的一部分製作過程
要設置圖像的樣式,您需要處理該文件的輸出

您是否有代碼爲客戶端生成HTML
如果是這樣的話,給每一個img類,並使用CSS給它的角落

.ui-corner-all { -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; } 
+0

是的,我現在看到它我出於某種原因考慮它的方式,你的這就是爲什麼我無法弄清楚如何將其納入該文件,因爲它不實際。謝謝。 – 2012-08-15 00:35:41