|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
PHP代码:-------------------------------------------------------------------------------- <? $FILENAME="image_name"; // 生成图片的宽度 $RESIZEWIDTH=400; // 生成图片的高度 $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; } 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 . ".jpg"); ImageDestroy ($newim); }else{ ImageJpeg ($im,$name . ".jpg"); } } if($_FILES[\\'image\\'][\\'size\\']){ if($_FILES[\\'image\\'][\\'type\\'] == "image/pjpeg"){ $im = imagecreatefromjpeg($_FILES[\\'image\\'][\\'tmp_name\\']); }elseif($_FILES[\\'image\\'][\\'type\\'] == "image/x-png"){ $im = imagecreatefrompng($_FILES[\\'image\\'][\\'tmp_name\\']); }elseif($_FILES[\\'image\\'][\\'type\\'] == "image/gif"){ $im = imagecreatefromgif($_FILES[\\'image\\'][\\'tmp_name\\']); } if($im){ if(file_exists("$FILENAME.jpg")){ unlink("$FILENAME.jpg"); } ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME); ImageDestroy ($im); } } ?> <img src="<? echo($FILENAME.".jpg?reload=".rand(0,999999)); ?>"><br><br> <form enctype="multipart/form-data" method="post"> <br> <input type="file" name="image" size="50" value="浏览"><p> <input type="submit" value="上传图片"> </form> </body> </html> 返回类别: 教程 上一教程: PHP教程.应用实例14 下一教程: ArrayAccess接口介绍 您可以阅读与"图片上传的一个例子"相关的教程: · PHP 存取 MySQL 数据库的一个例子 · 这是我在做的一个系统中的新闻增加程序,可以上传图片,也可以输入绝对大于4K的内容(在textarea中),... · 在PHP中得到多选的下拉菜单的各项值(一个例子) · 用PHP实现给上传的图片加水印的代码 · 怎样上传文件并存入数据库,给个例子 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |