最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php生成图片与验证码图片生成原理
时间:2022-06-24 21:13:18 编辑:袖梨 来源:一聚教程网
| 代码如下 | 复制代码 |
| $w?$RESIZEWIDTH=$w:$RESIZEWIDTH=400;// 生成图片的宽度 $h?$RESIZEHEIGHT=$h:$RESIZEHEIGHT=400;// 生成图片的高度 function ResizeImage($im,$maxwidth,$maxheight,$name){ $width = imagesx($im); $height = imagesy($im); if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){ if($maxwidth && $width > $maxwidth){ $widthratio = $maxwidth/$width; $RESIZEWIDTH=true;//www.111com.net } if($maxheight && $height > $maxheight){ $heightratio = $maxheight/$height; $RESIZEHEIGHT=true; } if($RESIZEWIDTH && $RESIZEHEIGHT){ if($widthratio < $heightratio){ $ratio = $widthratio; }else{ $ratio = $heightratio; } }elseif($RESIZEWIDTH){ $ratio = $widthratio; }elseif($RESIZEHEIGHT){ $ratio = $heightratio; } $newwidth = $width * $ratio; $newheight = $height * $ratio; if(function_exists("imagecopyresampled")){ $newim = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ $newim = imagecreate($newwidth, $newheight); imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); } ImageJpeg ($newim,$name); ImageDestroy ($newim); }else{ ImageJpeg ($im,$name); } } |
|
| 代码如下 | 复制代码 |
| if($_FILES['uploadfile']['size']){ if($_FILES['uploadfile']['type'] == "image/pjpeg"){ $im = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']); }elseif($_FILES['uploadfile']['type'] == "image/x-png"){ $im = imagecreatefrompng($_FILES['uploadfile']['tmp_name']); }elseif($_FILES['uploadfile']['type'] == "image/gif"){ $im = imagecreatefromgif($_FILES['uploadfile']['tmp_name']); } if($im){ if(file_exists('bbs.jpg')){ unlink('www.111com.net.jpg'); } ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,'bbs.jpg'); ImageDestroy ($im); } } //$uploadfile="bbs.jpg"; |
|
?>
创建图片后记得用ImageDestroy 清空内存哦。
相关文章
- TikTok国际版官网下载入口-安全访问全球版TikTok 12-15
- 新三国志曹操传马超无双试炼四通关攻略 12-15
- 俄罗斯YANDEX引擎官网入口-免登录直达Yandex首页 12-15
- 漫蛙ManWa在线免费阅读入口_漫蛙ManWa官方网页版一键直达 12-15
- 逃离鸭科夫仓库区地窖在哪 仓库区地窖入口位置详情 12-15
- 光与影33号远征队熙艾尔bd玩法:熙艾尔毕业装备与加点思路介绍 12-15