Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php,自动调整图像大小正在工作。但它存储在本地,我想保存在单独的文件夹中_Php_Html_Mysql - Fatal编程技术网

php,自动调整图像大小正在工作。但它存储在本地,我想保存在单独的文件夹中

php,自动调整图像大小正在工作。但它存储在本地,我想保存在单独的文件夹中,php,html,mysql,Php,Html,Mysql,这是我调整大小后的代码。图像直接存储在本地文件夹中。我已更改为指定文件夹 function imagecrop($img_name,$newname,$type,$modwidth,$modheight) { list($width, $height) = getimagesize($img_name) ; //get width & height in array list $tn = imagecreatetruecolor($modwid

这是我调整大小后的代码。图像直接存储在本地文件夹中。我已更改为指定文件夹

    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'>";
  }
    } 
函数imagecrop($img_name、$newname、$type、$modwidth、$modheight)
{
list($width,$height)=getimagesize($img_name);//获取数组列表中的宽度和高度
$tn=ImageCreateTureColor($modwidth,$modheight);
如果(!strcmp(“图像/png,$type))
{
imagealphablending($tn,false);//用于透明背景
imagesavealpha($tn,true);
}
如果(!strcmp(“image/jpg”,$type)| |!strcmp(“image/jpeg”,$type)| |!strcmp(“image/pjpeg”,$type))
$src_img=imagecreatefromjpeg($img_name);
如果(!strcmp(“图像/png,$type))
$src_img=imagecreatefrompng($img_name);
如果(!strcmp(“图像/gif”,$type))
$src_img=imagecreatefromformgif($img_name);
imagecopyresampled($tn、$src_img、0、0、0、$modwidth、$modheight、$width、$height、$height);
如果(!strcmp(“图像/png,$type))
{
imagesavealpha($src_img,true);
$ok=imagepng($tn,$newname);
}
else如果(!strcmp(“图像/gif”,$type))
{
$ok=imagegif($tn,$newname);
}
其他的
{
$ok=imagejpeg($tn,$newname);
}
如果($ok==1)
{
返回“”;
}
} 

保存新图像时,需要给出新图像的路径。尝试以下代码

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'>";
  }
    } 
函数imagecrop($img_name、$newname、$type、$modwidth、$modheight)
{
$newname=“/home/public_html/images/$newname”;//只是一个例子
list($width,$height)=getimagesize($img_name);//获取数组列表中的宽度和高度
$tn=ImageCreateTureColor($modwidth,$modheight);
如果(!strcmp(“图像/png,$type))
{
imagealphablending($tn,false);//用于透明背景
imagesavealpha($tn,true);
}
如果(!strcmp(“image/jpg”,$type)| |!strcmp(“image/jpeg”,$type)| |!strcmp(“image/pjpeg”,$type))
$src_img=imagecreatefromjpeg($img_name);
如果(!strcmp(“图像/png,$type))
$src_img=imagecreatefrompng($img_name);
如果(!strcmp(“图像/gif”,$type))
$src_img=imagecreatefromformgif($img_name);
imagecopyresampled($tn、$src_img、0、0、0、$modwidth、$modheight、$width、$height、$height);
如果(!strcmp(“图像/png,$type))
{
imagesavealpha($src_img,true);
$ok=imagepng($tn,$newname);
}
else如果(!strcmp(“图像/gif”,$type))
{
$ok=imagegif($tn,$newname);
}
其他的
{
$ok=imagejpeg($tn,$newname);
}
如果($ok==1)
{
返回“”;
}
} 

在输出图像函数(imagepng、imagegif、imagejpeg)的第二个参数中添加目标路径。从PHP手册:

文件名-保存文件的路径。如果未设置或为NULL,则原始 图像流将直接输出