2011-01-10 5 views
1

私は、画像にエッジを丸めて特定のサイズまで動的に広告を作っています。現時点では、スクリプトは画像に丸みを帯びたエッジを表示しますが、元の画像が最終的に出力される画像(140ピクセル×120ピクセル)のサイズに収まるようにサイズ変更できません。問題は、元のPHP画像のサイズを変更して画像の角を丸く丸くします

私の質問は、それは丸いエッジで処理された140×120の画像に収まるようreized orginal画像を取得する方法である:寸法は、それが最終的なPNG

{ 
$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"; 

    } 

EDITであるサイズを変更しますか?

+2

あなたの質問は何ですか? –

+5

サイズを変更した後に丸めを追加しませんか? – DampeS8N

答えて

0

ここでは、アスペクト比を維持するためにトリミングまたはレターボックスを使用して、イメージを任意のサイズにリサイズするPHP関数へのリンクです。それはかなり徹底した説明をしています。ただし、サイズ変更後に丸みのあるエッジを追加したい場合があります。

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

関連する問題