這款php生成圖片與驗證碼圖片生成原理代碼,是由php gd庫來支持,如果你的系統不能創建圖片就把gd.dll前面的;去再,重起apache,如果是iis重起iis就OK了.創建圖片后記得用ImageDestroy 清空內存.
php生成圖片與驗證碼圖片實例代碼如下:
- $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.49028c.com
- }
- 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.49028c.com.jpg');
- }
- ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,'bbs.jpg');
- ImageDestroy ($im);
- }
- }
- //$uploadfile="bbs.jpg";
新聞熱點
疑難解答