- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章php制作中间带自己定义图片二维码的方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
1,首先你必须生成二维码具体代码如下:
复制代码 代码如下
class QRCode{ public $w; public $h; public $s; function __construct($w1,$h1,$s1){ $this->w = $w1; $this->h = $h1; $this->s = $s1; $this->outimgase(); } function qrcode(){ $post_data = array(); $post_data['cht'] = 'qr'; $post_data['chs'] = $this->w."x".$this->h; $post_data['chl'] = $this->s; $post_data['choe'] = "UTF-8"; $url = "http://chart.apis.google.com/chart"; $data_Array = array(); foreach($post_data as $key => $value) { $data_Array[] = $key.'='.$value; } $data = implode("&",$data_Array); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); return $result; } function outimgase(){ echo $this->qrcode(); } } header("Content-type:image/png"); $t = new QRCode(300,300,"tianxin"),
2,然后通过一个php文件将二维码和你的目的图片画在一起代码如下: <?php 。
复制代码 代码如下
$surl = $_POST["url"]; function GrabImage($url,$filename="") { if($url==""):return false;endif; if($filename=="") { $ext=strrchr($url,"."); if($ext!=".gif" && $ext!=".jpg"):return false;endif; $filename=date("dMYHis").$ext; } ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); $size = strlen($img); $fp2=@fopen($filename, "a"); fwrite($fp2,$img); fclose($fp2); return $filename; } $source = GrabImage("http://localhost/QRCode/QRCode.php","Myqrcode.png"); $water =GrabImage($surl,"t.png"); function getImageInfo($img){ $imageInfo = getimagesize($img); if ($imageInfo !== false) { $imageType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1)); $imageSize = filesize($img); $info = array( "width" => $imageInfo[0], "height" => $imageInfo[1], "type" => $imageType, "size" => $imageSize, "mime" => $imageInfo['mime'] ); return $info; } else { return false; } } function thumb($image, $thumbname, $type='', $maxWidth=200, $maxHeight=50, $interlace=true) { // 获取原图信息 $info = getImageInfo($image); if ($info !== false) { $srcWidth = $info['width']; $srcHeight = $info['height']; $type = empty($type) ? $info['type'] : $type; $type = strtolower($type); $interlace = $interlace ? 1 : 0; unset($info); $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight); // 计算缩放比例 if ($scale >= 1) { // 超过原图大小不再缩略 $width = $srcWidth; $height = $srcHeight; } else { // 缩略图尺寸 $width = (int) ($srcWidth * $scale); $height = (int) ($srcHeight * $scale); } // 载入原图 $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type); $srcImg = $createFun($image); //创建缩略图 if ($type != 'gif' && function_exists('imagecreatetruecolor')) $thumbImg = imagecreatetruecolor($width, $height); else $thumbImg = imagecreate($width, $height); // 复制图片 if (function_exists("ImageCopyResampled")) imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight); else imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight); if ('gif' == $type || 'png' == $type) { //imagealphablending($thumbImg, false);//取消默认的混色模式 //imagesavealpha($thumbImg,true);//设定保存完整的 alpha 通道信息 $background_color = imagecolorallocate($thumbImg, 0, 255, 0); // 指派一个绿色 imagecolortransparent($thumbImg, $background_color); // 设置为透明色,若注释掉该行则输出绿色的图 } // 对jpeg图形设置隔行扫描 if ('jpg' == $type || 'jpeg' == $type) imageinterlace($thumbImg, $interlace); // 生成图片 $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type); $imageFun($thumbImg, $thumbname); imagedestroy($thumbImg); imagedestroy($srcImg); return $thumbname; } return false; } function water($source, $thumb, $savename="", $alpha=100){ //检查文件是否存在 if (!file_exists($source) || !file_exists($thumb)) return false; //图片信息 $sInfo = getImageInfo($source); $water = thumb($thumb,"wy.jpg","jpg",$sInfo["width"]/4,$sInfo["height"]/4); $wInfo = getImageInfo($water); //如果图片小于水印图片,不生成图片 if ($sInfo["width"] < $wInfo["width"] || $sInfo['height'] < $wInfo['height']) return false; //建立图像 $sCreateFun = "imagecreatefrom" . $sInfo['type']; $sImage = $sCreateFun($source); $wCreateFun = "imagecreatefrom" . $wInfo['type']; $wImage = $wCreateFun($water); //设定图像的混色模式 imagealphablending($wImage, true); //图像位置,默认为右下角右对齐 // $posY = $sInfo["height"] - $wInfo["height"]; // $posX = $sInfo["width"] - $wInfo["width"]; $posY = ($sInfo["height"] - $wInfo["height"])/2; $posX = ($sInfo["width"] - $wInfo["width"])/2; //生成混合图像 imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo['width'], $wInfo['height'], $alpha); //输出图像 $ImageFun = 'Image' . $sInfo['type']; //如果没有给出保存文件名,默认为原图像名 if (!$savename) { $savename = $source; @unlink($source); } //保存图像 $ImageFun($sImage, $savename); imagedestroy($sImage); } water($source,$water),
在上面的代码中用3个函数 GrabImage()函数是将生成二维码的文件转化成图片 接下来的函数就是处理图片的缩放 将目的图片添加到二位上。 3,在来一个入口文件index.html 代码如下:
复制代码 代码如下
<html> <head> <title> 中间可以自己定义图片的二维码生成器 </title> </head> <body style="margin:0px; padding:0px; font-family:宋体; font-size:12px;"> <form action="<span style="font-size:18px;"><strong><span style="color:#FF0000;">注意提交的URL</span></strong></span>" method="post"> <div style="width:500px; height:200px; background-color:#CCCCCC; margin:auto; border-width:1px; border-color:#000000;" align="center"> <h1 style="margin:0px; padding:20px; font-family:宋体; font-size:12px;">中间可以自己定义图片的二维码生成器</h1> <table width="500" border="0"> <tr> <td width="250" height="40" align="center" valign="middle">二维码要生的内容:</td> <td width="250" height="40" align="center" valign="middle"> <label> <input type="text" name="content" value=""> </label> </td> </tr> <tr> <td width="250" height="40" align="center" valign="middle">希望能添加自己的图片地址:</td> <td width="250" height="40" align="center" valign="middle"> <label> <input type="text" name="url" value=""> </label> </td> </tr> <tr> <td height="40" colspan="2" align="center" valign="middle"> <label> <input type="submit" name="Submit" value="生成我想要的二维码"> </label> </td> </tr> </table> </div> </body> </html> 。
最后此篇关于php制作中间带自己定义图片二维码的方法的文章就讲到这里了,如果你想了解更多关于php制作中间带自己定义图片二维码的方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我想了解 Ruby 方法 methods() 是如何工作的。 我尝试使用“ruby 方法”在 Google 上搜索,但这不是我需要的。 我也看过 ruby-doc.org,但我没有找到这种方法。
Test 方法 对指定的字符串执行一个正则表达式搜索,并返回一个 Boolean 值指示是否找到匹配的模式。 object.Test(string) 参数 object 必选项。总是一个
Replace 方法 替换在正则表达式查找中找到的文本。 object.Replace(string1, string2) 参数 object 必选项。总是一个 RegExp 对象的名称。
Raise 方法 生成运行时错误 object.Raise(number, source, description, helpfile, helpcontext) 参数 object 应为
Execute 方法 对指定的字符串执行正则表达式搜索。 object.Execute(string) 参数 object 必选项。总是一个 RegExp 对象的名称。 string
Clear 方法 清除 Err 对象的所有属性设置。 object.Clear object 应为 Err 对象的名称。 说明 在错误处理后,使用 Clear 显式地清除 Err 对象。此
CopyFile 方法 将一个或多个文件从某位置复制到另一位置。 object.CopyFile source, destination[, overwrite] 参数 object 必选
Copy 方法 将指定的文件或文件夹从某位置复制到另一位置。 object.Copy destination[, overwrite] 参数 object 必选项。应为 File 或 F
Close 方法 关闭打开的 TextStream 文件。 object.Close object 应为 TextStream 对象的名称。 说明 下面例子举例说明如何使用 Close 方
BuildPath 方法 向现有路径后添加名称。 object.BuildPath(path, name) 参数 object 必选项。应为 FileSystemObject 对象的名称
GetFolder 方法 返回与指定的路径中某文件夹相应的 Folder 对象。 object.GetFolder(folderspec) 参数 object 必选项。应为 FileSy
GetFileName 方法 返回指定路径(不是指定驱动器路径部分)的最后一个文件或文件夹。 object.GetFileName(pathspec) 参数 object 必选项。应为
GetFile 方法 返回与指定路径中某文件相应的 File 对象。 object.GetFile(filespec) 参数 object 必选项。应为 FileSystemObject
GetExtensionName 方法 返回字符串,该字符串包含路径最后一个组成部分的扩展名。 object.GetExtensionName(path) 参数 object 必选项。应
GetDriveName 方法 返回包含指定路径中驱动器名的字符串。 object.GetDriveName(path) 参数 object 必选项。应为 FileSystemObjec
GetDrive 方法 返回与指定的路径中驱动器相对应的 Drive 对象。 object.GetDrive drivespec 参数 object 必选项。应为 FileSystemO
GetBaseName 方法 返回字符串,其中包含文件的基本名 (不带扩展名), 或者提供的路径说明中的文件夹。 object.GetBaseName(path) 参数 object 必
GetAbsolutePathName 方法 从提供的指定路径中返回完整且含义明确的路径。 object.GetAbsolutePathName(pathspec) 参数 object
FolderExists 方法 如果指定的文件夹存在,则返回 True;否则返回 False。 object.FolderExists(folderspec) 参数 object 必选项
FileExists 方法 如果指定的文件存在返回 True;否则返回 False。 object.FileExists(filespec) 参数 object 必选项。应为 FileS
我是一名优秀的程序员,十分优秀!