2011-01-10 136 views
1

我正在工作的一個腳本,動態地向圖像廣告圓角邊緣然後裁剪到一定的大小。目前,腳本在圖片上展示了圓角邊緣,但我無法得到它,原始圖片的大小被調整爲適合最終輸出圖片的尺寸(140px x 120px)。問題是,原始上傳的圖片取決於它的原始數據尺寸改變它的大小是在最後PNGPHP圖像調整大小和動態圓角圖像角

{ 
$image_file = $_FILES['image']['tmp_name']; 

    $corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px 
    $topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is shown by default 
    $bottomleft = (isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // Bottom-left rounded corner is shown by default 
    $bottomright = (isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // Bottom-right rounded corner is shown by default 
    $topright = (isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // Top-right rounded corner is shown by default 
    $imagetype=$_FILES['image']['type']; 

    $endsize=$corner_radius; 
    $startsize=$endsize*3-1; 
    $arcsize=$startsize*2+1; 

    if (($imagetype=='image/jpeg') or ($imagetype=='jpg')) { 
    $image = imagecreatefromjpeg($image_file); 
    } else { 
    if (($imagetype=='GIF') or ($imagetype=='gif')) { 
    $image = imagecreatefromgif($image_file); 
    } else { 
    $image = imagecreatefrompng($image_file); 
    } 
    } 

    $forecolor ='#ffffff'; 
    $size = getimagesize($image_file); 
    // Top-left corner 
    $background = imagecreatetruecolor($size[0],$size[1]); 
    imagecopymerge($background, $image, 0, 0, 0, 0, $size[0], $size[1], 100); 
    $startx=$size[0]*2-1; 
    $starty=$size[1]*2-1; 
    $im_temp = imagecreatetruecolor($startx,$starty); 
    imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $size[0], $size[1]); 
    $bg = imagecolorallocate($im_temp, 255,255,255); 
    $fg = imagecolorallocate($im_temp, 255,255,255); 

    if ($topleft == true) { 
    if(!imagearc($im_temp, $startsize, $startsize, $arcsize, $arcsize, 180,270,$bg))echo "nope"; 
    imagefilltoborder($im_temp,0,0,$bg,$bg); 
    } 
    // Bottom-left corner 

    // Top-right corner 
    if ($topright == true) { 
    imagearc($im_temp, $startx-$startsize, $startsize,$arcsize, $arcsize, 270,360,$bg); 
    imagefilltoborder($im_temp,$startx,0,$bg,$bg); 
    } 


    $image = imagecreatetruecolor(140,120); 
    imagecopyresampled($image, $im_temp, 0, 0, 0, 0, $size[0],$size[1],$starty+1310,$startx+1500); 


    // Output final image 


    if(!imagepng($image,'hello.png')) echo "boo"; 
    if(!imagedestroy($image)) echo "2"; 
    if(!imagedestroy($background)) echo "3"; 
    if(!imagedestroy($im_temp)) echo "4"; 

    } 

編輯:

我的問題是如何讓原單圖像reized所以它適合與該圓邊處理的140×120的圖像?

+2

但是你的問題是什麼? – 2011-01-10 13:28:03

回答

0

這裏是一個PHP函數的鏈接,它可以將任何圖像的大小調整爲任意大小,使用裁剪或拼音來保持寬高比。它有一個相當徹底的解釋。然而,您將需要在調整大小後添加圓角邊緣。

http://www.spotlesswebdesign.com/blog.php?id=1