$newWidth=600;

$file_path='D:/myWorkspace/get_img/deal_img/jiaShuiYin/1.jpg';

$newName='D:/myWorkspace/get_img/deal_img/jiaShuiYin/2.jpg';

resizeImage($newWidth,$file_path,$newName);

 

/*
功能:按规定宽度等比压缩图片(压缩后图片的大小也会被压缩)
*/
function resizeImage($maxwidth,$file_path,$name)
{

$im=imagecreatefromjpeg($file_path);
$pic_width = imagesx($im);
$pic_height = imagesy($im);

if($maxwidth && $pic_width > $maxwidth)
{
$ratio = $maxwidth/$pic_width;

$newwidth = $maxwidth;
$newheight = $pic_height * $ratio;
if(function_exists("imagecopyresampled"))
{
$newim = imagecreatetruecolor($newwidth,$newheight);
$state=imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
}else
{
$newim = imagecreate($newwidth,$newheight);
$state=imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
}
if($state)
{
if(!imagejpeg($newim,$name)){
write_log($name,"图片写入出错");
}
imagedestroy($newim);
}else
{
write_log($name,"图片写入出错");
}
}else
{
if (!copy($file_path,$name)) {
write_log($name,"图片copy出错");
}
}
}

相关文章:

  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2021-12-15
猜你喜欢
  • 2021-07-20
  • 2022-12-23
  • 2021-07-22
  • 2021-11-22
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
相关资源
相似解决方案