0

これは、画像のサイズを変更した後の私のコードで、ローカルフォルダーに直接保存されます。指定したフォルダーに変更しました。

    function imagecrop($img_name,$newname,$type,$modwidth,$modheight)
    {

list($width, $height) = getimagesize($img_name) ; //get width & height in array         list

    $tn = imagecreatetruecolor($modwidth, $modheight); 
if(!strcmp("image/png",$type))
{
imagealphablending($tn, false); //For transparent BackGround
imagesavealpha($tn, true);  
}



   if(!strcmp("image/jpg",$type) || !strcmp("image/jpeg",$type) || !strcmp("image/pjpeg",$type))
    $src_img=imagecreatefromjpeg($img_name);

    if(!strcmp("image/png",$type))
    $src_img=imagecreatefrompng($img_name);

    if(!strcmp("image/gif",$type))
        $src_img=imagecreatefromgif($img_name);

      imagecopyresampled($tn, $src_img, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 


       if(!strcmp("image/png",$type))  
       {
   imagesavealpha($src_img, true);
   $ok=imagepng($tn,$newname);
       }
   else if(!strcmp("image/gif",$type))  
       {
   $ok=imagegif($tn,$newname);
   }
       else 
   {
       $ok=imagejpeg($tn,$newname);
   }

    if($ok==1)
  {
    return "<img src=".$_FILES['userfile']['name']." border='0'>";
  }
    } 
4

2 に答える 2

0

保存するときに、新しい画像のパスを指定する必要があります。次のコードを試してください

function imagecrop($img_name,$newname,$type,$modwidth,$modheight)
{

    $newname = "/home/public_html/images/$newname"; //just an example


    list($width, $height) = getimagesize($img_name) ; //get width & height in array         list

    $tn = imagecreatetruecolor($modwidth, $modheight); 
    if(!strcmp("image/png",$type))
    {
       imagealphablending($tn, false); //For transparent BackGround
       imagesavealpha($tn, true);  
    }



   if(!strcmp("image/jpg",$type) || !strcmp("image/jpeg",$type) || !strcmp("image/pjpeg",$type))
    $src_img=imagecreatefromjpeg($img_name);

    if(!strcmp("image/png",$type))
    $src_img=imagecreatefrompng($img_name);

    if(!strcmp("image/gif",$type))
        $src_img=imagecreatefromgif($img_name);

      imagecopyresampled($tn, $src_img, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 


       if(!strcmp("image/png",$type))  
       {
   imagesavealpha($src_img, true);
   $ok=imagepng($tn,$newname);
       }
   else if(!strcmp("image/gif",$type))  
       {
   $ok=imagegif($tn,$newname);
   }
       else 
   {
       $ok=imagejpeg($tn,$newname);
   }

    if($ok==1)
  {
    return "<img src=".$_FILES['userfile']['name']." border='0'>";
  }
    } 
于 2013-03-29T07:24:43.790 に答える
0

出力画像関数 (imagepng、imagegif、imagejpeg) の 2 番目の引数にターゲット パスを追加します。PHPマニュアルから:

filename - ファイルを保存するパス。設定されていないか NULL の場合、生の画像ストリームが直接出力されます。

于 2013-03-29T07:27:15.193 に答える