- Class qrcode{
- public $w;
- Public $h;
- Public $s;
- function __construct ($w 1, $h 1, $s 1) {
- $this->w = $w 1;
- $this->h = $h 1;
- $this->s = $s 1;
- $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");
Copy Code2, and then, through a PHP file will be the QR code and your purpose picture to draw together.
$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);
- $FP 2= @fopen ($filename, "a");
- Fwrite ($fp 2, $img);
- Fclose ($fp 2);
- 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) {
- Get the original information
- $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); Calculating the zoom ratio
- if ($scale >= 1) {
- More than the original size is no longer abbreviated
- $width = $srcWidth;
- $height = $srcHeight;
- } else {
- Thumbnail size
- $width = (int) ($srcWidth * $scale);
- $height = (int) ($srcHeight * $scale);
- }
- Load in original
- $createFun = ' Imagecreatefrom '. ($type = = ' jpg '? ' JPEG ': $type);
- $SRCIMG = $createFun ($image);
- Create a thumbnail image
- if ($type! = ' gif ' && function_exists (' Imagecreatetruecolor '))
- $THUMBIMG = Imagecreatetruecolor ($width, $height);
- Else
- $THUMBIMG = Imagecreate ($width, $height);
- Copy Picture
- 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);//Cancel the default process color mode
- Imagesavealpha ($THUMBIMG, true);//set to save full alpha channel information
- $background _color = imagecolorallocate ($thumbImg, 0, 255, 0); Assign a Green
- Imagecolortransparent ($THUMBIMG, $background _color); Set to Transparent color, if the line is commented out the output of the green graph
- }
- Set up interlaced scanning for JPEG graphics
- if (' jpg ' = = $type | | ' jpeg ' = = $type)
- Imageinterlace ($THUMBIMG, $interlace);
Create a picture
- $imageFun = ' image '. ($type = = ' jpg '? ' JPEG ': $type);
- $imageFun ($THUMBIMG, $thumbname);
- Imagedestroy ($THUMBIMG);
- Imagedestroy ($SRCIMG);
- return $thumbname;
- }
- return false;
- }
- function water ($source, $thumb, $savename = "", $alpha =100) {
- Check if the file exists
- if (!file_exists ($source) | |!file_exists ($THUMB))
- return false;
- Picture information
- $sInfo = Getimageinfo ($source);
- $water = Thumb ($thumb, "wy.jpg", "jpg", $sInfo ["width"]/4, $sInfo ["height"]/4);
- $wInfo = Getimageinfo ($water);
- If the picture is smaller than the watermark picture, the picture is not generated
- if ($sInfo ["width"] < $wInfo ["width"] | | $sInfo [' height '] < $wInfo [' height '])
- return false;
- Create an image
- $sCreateFun = "Imagecreatefrom". $sInfo [' type '];
- $sImage = $sCreateFun ($source);
- $wCreateFun = "Imagecreatefrom". $wInfo [' type '];
- $wImage = $wCreateFun ($water);
- To set the color blending mode of an image
- Imagealphablending ($wImage, true);
- Image position, default to right bottom right corner
- $posY = $sInfo ["height"]-$wInfo ["height"];
- $posX = $sInfo ["width"]-$wInfo ["width"];
- $posY = ($sInfo ["height"]-$wInfo ["height"])/2;
- $posX = ($sInfo ["width"]-$wInfo ["width"])/2;
- Generating mixed images
- Imagecopymerge ($sImage, $wImage, $posX, $posY, 0, 0, $wInfo [' width '], $wInfo [' height '], $alpha);
- Output image
- $ImageFun = ' Image '. $sInfo [' type '];
- If the save file name is not given, the original image name is the default
- if (! $savename) {
- $savename = $source;
- @unlink ($source);
- }
- Save Image
- $ImageFun ($sImage, $savename);
- Imagedestroy ($sImage);
- }
- Water ($source, $water);
Copy CodeIn the code above, 3 functions Grabimage () function is to convert a file that generates a QR code into a picture the next function is to manipulate the image's zoom to add the destination image to the two-bit. 3, in a portal file index.html code is as follows:
- A two-dimensional code generator that can define its own image in the middle _bbs.it-home.org
- Note the URL of the submission"method=" POST ">
A two-dimensional code generator that can define a picture in the middle
Two-dimensional code to be raw content: |
|
Want to add your own image address: |
|
|
Copy Code |