导航:首页 > 图片大全 > 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如何缩放图片相关的资料

热点内容
最美的新娘发型图片 浏览:469
女孩子喜欢希的图片 浏览:703
老年人夏季发型图片 浏览:9
丁子裤美女的图片 浏览:528
黑色简约文字图片 浏览:716
美女跳楼图片 浏览:33
卷发长发发型图片韩版 浏览:869
男人刘海发型图片大全 浏览:18
简单新娘头发造型图片 浏览:184
美女小便的地方图片 浏览:332
word图片设置不透明 浏览:966
男生背部抓痕图片 浏览:478
搞笑美女剪头发图片 浏览:233
如何把图片弄成格子画的形式 浏览:267
动漫女生裸睡图片 浏览:58
男生黑裤子配白鞋图片 浏览:330
一直走下去的图片文字 浏览:695
word图片灰暗如何调节对比度 浏览:247
word文档如何横放3张图片 浏览:59
简单竹画图片大全图片 浏览:712