2017-08-10 17 views
-2

pngとgifイメージのサイズを変更し、PHPを使用して透明な背景を保存するには?PHPでイメージの背景色を黒から透明に変更する方法は?

これは私のコード

あなたは200×200ピクセルに画像のサイズを変更し、PIEのディレクトリに登るあります。それは良い仕事です。しかし、pngまたはgifイメージ(透明なbg)とともに使用されたとき。 bgを黒に変えます。画像のサイズを変更した後に透明なbgを作成するにはどうすればよいですか?

オリジナル:

http://imgur.com/a/8FicX

コピー:

http://imgur.com/a/7yQo8

include 'compressImage.php'; 
    <?php 
    $widthArray = array(200); 
    foreach($widthArray as $newwidth) 
    {      
     compressImage($ext,$tmp,$path,$userID.$actual_image_name,$newwidth); 
    } 
    ?> 

compressImage.php:

<?php 
//Compress Image 
function compressImage($ext,$uploadedfile,$path,$actual_image_name,$newwidth) 
{ 
    if($ext=="jpg" || $ext=="jpeg") 
    { 
    $src = imagecreatefromjpeg($uploadedfile); 
    } 
    else if($ext=="png") 
    { 
    $src = imagecreatefrompng($uploadedfile); 
    } 
    else if($ext=="gif") 
    { 
    $src = imagecreatefromgif($uploadedfile); 
    } 
    else 
    { 
    $src = imagecreatefrombmp($uploadedfile); 
    } 

    list($width,$height)=getimagesize($uploadedfile); 
    $newheight=($height/$width)*$newwidth; 
    $tmp=imagecreatetruecolor($newwidth,$newheight); 
    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 
    $filename = $path.$newwidth.'_'.$actual_image_name; 
    imagejpeg($tmp,$filename,100); 
    imagedestroy($tmp); 
    return $filename; 
} 
?> 
+0

https://es.stackoverflow.com/q/94015/29516 – Shareiv

答えて

関連する問題