<?php imgshuiyin("./img/1.jpg",'./img/6.jpg',100,100); function imgshuiyin($dname,$wname,$pos=7,$tou=50){ //img(主图1,主图2,位置,透明度) function imgclass($name){ $img_info=getimagesize($name); //getimagesize($dname)函数可以动态的获取图片类型,大小,宽度和高度等 $img_width=$img_info[0]; $img_height=$img_info[1]; $img_mime=$img_info['mime']; //根据类型来判断资源 switch ($img_mime) { case 'image/jpeg': $img=imagecreatefromjpeg($name); break; case 'image/gif': $img=imagecreatefromgif($name); break; case 'image/png': $img=imagecreatefrompng($name); break; case 'image/wbmp': $img=imagecreatefromwbmp($name); break; } return array('width'=>$img_width,'height'=>$img_height,'res'=>$img); } $dst_info=imgclass($dname); $water_info=imgclass($wname); //getimagesize($dname)函数可以动态的获取图片类型,大小,宽度和高度等 $dst_width=$dst_info['width']; $dst_height=$dst_info['height']; $water_width=$water_info['width']; $water_height=$water_info['height']; $water=$water_info['res']; $dst=$dst_info['res']; /* 输出:array(3) { ["width"]=> int(3104) ["height"]=> int(4192) ["mime"]=> string(10) "image/jpeg" } array(3) { ["width"]=> int(1470) ["height"]=> int(1391) ["mime"]=> string(10) "image/jpeg" } */ switch ($pos) { case 1: $x=0; $y=0; break; case 2: $x=$dst_width/2-$water_width/2; $y=0; break; case 3: $x=$dst_width-$water_width; $y=0; break; case 4: $x=0; $y=$dst_height/2-$water_height/2; break; case 5: $x=$dst_width/2-$water_width/2; $y=$dst_height/2-$water_height/2; break; case 6: $x=$dst_width-$water_height; $y=$dst_height/2-$water_height/2; break; case 7: $x=0; $y=$dst_height-$water_height; break; case 8: $x=$dst_width/2-$water_height/2; $y=$dst_height-$water_height; break; case 9: $x=$dst_width-$water_height; $y=$dst_height-$water_height; break; } imagecopymerge($dst,$water,$x,$y,0,0,$water_width,$water_height,$tou); header("content-type:image/png"); imagepng($dst,'./img/6.jpg');//可以自定义参数imagepng($dst,1.png);会自动生成1.png图像,最好随机生成 imagedestroy($dst); imagedestroy($water); }
imagepng 保存后图片非常达到1m多 原来仅是100k,该怎么处理 下面是代码
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 歇歇 2021-02-21 19:20关注
PNG是一种无损格式,对于通常以JPEG文件压缩的照片和其他复杂图像,不会产生良好的压缩率。
更如果要将JPEG文件转换为PNG,则PNG还必须逐像素再现由JPEG有损压缩引起的压缩伪像。文件会变大。文件大小又图片像素值决定,您可以缩小图片的分辨率(长,宽)来缩小png文件
quality
压缩级别:从0(无压缩)到9。默认(
-1
)使用zlib压缩默认值。有关更多信息,请参见»zlib手册。filters
允许减小PNG文件的大小。它是一个位掩码字段,可以将其设置为
PNG_FILTER_XXX
常量的任何组合。PNG_NO_FILTER
或者PNG_ALL_FILTERS
也可以分别用于禁用或激活所有过滤器。默认值(-1
)禁用过滤。采用楼上答案即可
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用