导航:首页 > 图片大全 > php如何缩放图片

php如何缩放图片

发布时间:2023-05-15 20:48:32

A. php 怎么压缩图片的大小

php压缩图片的大小:
<?php
$im=imagecreatefromjpeg('D:phpplace.jpeg');
resizeImage($im,,,'xinde','.jpg');
functionresizeImage($im,$maxwidth,$maxheight,$name,$filetype)
{
$pic_width=imagesx($im);
$pic_height=imagesy($im);
echo"start-----------------";
if(($maxwidth&&$pic_width>$maxwidth)&&($maxheight&&$pic_height>$maxheight))
{
if($maxwidth&&$pic_width>$maxwidth)
{
$widthratio=$maxwidth/$pic_width;
$resizewidth_tag=true;
}
if($maxheight&&$pic_height>$maxheight)
{
$heightratio=$maxheight/$pic_height;
$resizeheight_tag=true;
}
if($resizewidth_tag&&$resizeheight_tag)
{
if($widthratio<$heightratio)
$ratio=$widthratio;
else
$ratio=$heightratio;
}
if($resizewidth_tag&&!$resizeheight_tag)
$ratio=$widthratio;
if($resizeheight_tag&&!$resizewidth_tag)
$ratio=$heightratio;
$newwidth=$pic_width*$ratio;
$newheight=$pic_height*$ratio;
if(function_exists("imageresampled"))
{
$newim=imagecreatetruecolor($newwidth,$newheight);
imageresampled($newim,$im,,,,,$newwidth,$newheight,$pic_width,$pic_height);
}
else
{
$newim=imagecreate($newwidth,$newheight);
imageresized($newim,$im,,,,,$newwidth,$newheight,$pic_width,$pic_height);
}
$name=$name.$filetype;
imagejpeg($newim,$name);
imagedestroy($newim);
}
else
{
$name=$name.$filetype;
imagejpeg($im,$name);
}
}

B. php实现图片等比例缩放代码

新建文件index.php,需要在统计目录下有个图片为q.jpg(可根据源码进行更改图片的名称)
源代码如下:
<?php
$filename="q.jpg";
$per=0.3;
list($width,
$height)=getimagesize($filename);
$n_w=$width*$per;
$n_h=$height*$per;
$new=imagecreatetruecolor($n_w,
$n_h);
$img=imagecreatefromjpeg($filename);
//拷贝部分图像并调整
imageresized($new,
$img,0,
0,0,
0,$n_w,
$n_h,
$width,
$height);
//图像输出新图片、另存为
imagejpeg($new,
"q1.jpg");
imagedestroy($new);
imagedestroy($img);
?>
使用浏览器运行过后,在index.php同级的目录下会有个q1.jpg,这个图片就是等比例缩放后的图片,路径可以自己在源代码里面更改,放在自己的项目当中去或写个方法也行
以上所述上就是本文的全部内容了,希望对大家学习php语言能够有所帮助。

阅读全文

与php如何缩放图片相关的资料

热点内容
rado雷达价格及图片 浏览:512
悲伤带有文字的图片 浏览:955
萌女动漫的图片大全可爱图片 浏览:461
爱心牌衣服图片 浏览:203
发型师图片男动漫 浏览:632
气质锁骨发型图片直发 浏览:542
怎么对图片进行审美表述 浏览:246
word文档内如何旋转图片 浏览:973
樱花高清动漫图片 浏览:729
可爱的投影图片 浏览:160
半扎丸子头发型图片 浏览:789
女孩后脑勺高图片 浏览:2
ps怎么单独改变人物图片衣服颜色 浏览:344
日本动漫唯美图片大全 浏览:836
论文图片如何转换文字 浏览:173
word图片有一边边框不显示 浏览:534
word中怎样设置图片和纸张一样大 浏览:658
将图片覆盖在文字上 浏览:844
单身男生拥抱图片 浏览:852
男型发型图片 浏览:282