guojy 1 år sedan
förälder
incheckning
eec9602419
2 ändrade filer med 873 tillägg och 0 borttagningar
  1. 607 0
      src/view/course/home_qr2img_next.vue
  2. 266 0
      src/view/course/utils/convas2Images.js

+ 607 - 0
src/view/course/home_qr2img_next.vue

@@ -0,0 +1,607 @@
+<template>
+    <div class="curPage">
+      <div class="userInfo">
+        <van-row
+          type="flex"
+          class="imageName"
+          justify="space-between"
+          align="center"
+        >
+          <div class="userImage">
+            <userImage
+              class="about-me__avatar"
+              :img_url="user_info.imgUrl"
+              :user_name="user_info.name"
+              width="1.12rem"
+              height="1.12rem"
+              v-if="user_info.imgUrl"
+            ></userImage>
+            <div style="background: #26A2FF;border-radius: 50%;overflow: hidden;" v-else>
+              <userImage
+                class="about-me__avatar"
+                :img_url="defaultImgUrl"
+                user_name="用户"
+                width="1.12rem"
+                height="1.12rem"
+              ></userImage>
+            </div>
+            <div class="info">
+              <span
+                >{{ user_info.name ? user_info.name : "新用户"
+                }}<van-icon
+                  name="notes-o"
+                  color="#E1B98B"
+                  style="margin-left: .1rem;"
+              /></span>
+              <!-- <p>手机:{{ user_info.tel }}</p> -->
+              <!-- <p
+                class="userId"
+                :aria-label="user_info.id"
+                @click="copyLink('.userId')"
+              >
+                <i class="courseIcon icon-fuzhi"></i>复制身份ID
+              </p> -->
+            </div>
+          </div>
+          <div class="user_leave">
+            <van-icon name="gem-o" color="#a66666" />
+            {{ user_info.marketable ? "经销商" : "学员" }}
+          </div>
+        </van-row>
+      </div>
+      <div class="user_tabs" v-if="user_info.marketable">
+        <div class="tabs_content">
+          <div class="tabsLi" @click="toUrl('/courseTeam/1')">
+            <van-image
+              src="static/images/course_team.png"
+              style="width: .8rem;height: .8rem;"
+              type="contain"
+            />
+            <span>我的团队</span>
+          </div>
+          <div class="tabsLi" @click="qropen">
+            <van-image
+              src="static/images/course_ewm.png"
+              style="width: .8rem;height: .8rem;"
+              type="contain"
+            />
+            <span>邀请二维码</span>
+          </div>
+          <div class="tabsLi" @click="toUrl('/courseTeam/2')">
+            <van-image
+              src="static/images/course_dingdan.png"
+              style="width: .8rem;height: .8rem;"
+              type="contain"
+            />
+            <span>交易往来</span>
+          </div>
+        </div>
+      </div>
+      <div class="user_course_tabs" v-if='user_info.marketable'>
+        <van-tabs v-model="tbsIndex" style="width: 60%;">
+          <van-tab title="我的推广"></van-tab>
+          <van-tab title="我的学习"></van-tab>
+        </van-tabs>
+        <!-- <div class="tbsL" v-if='user_info.marketable'>
+          <div class="tbsi" :class="{active:tbsIndex==0}" @click="selectTbs(0)">我的推广</div>
+          <div class="tbsi" :class="{active:tbsIndex==1}" @click="selectTbs(1)">我的学习</div>
+        </div> -->
+        <div class="tbsR" v-if="user_info.marketable" @click="toMoreUrl">
+          <span>名额变动明细<van-icon name="arrow" /></span>
+        </div>
+      </div>
+      <!-- <van-search
+        v-model="wxId"
+        placeholder="请输入wxid替换当前账号"
+        show-action
+        style="margin: 0.1rem 0.2rem 0;border-radius: 0.1rem;"
+        @search="changeUSer"
+      /> -->
+      <div
+        class="courScroll"
+        :style="{
+          height: user_info.marketable
+            ? 'calc(100vh - 4.38rem) !important'
+            : 'calc(-2.05rem + 100vh) !important'
+        }"
+      >
+        <scroller ref="scroller" :isInitRefresh="false">
+          <van-loading
+            v-show="showLoad"
+            style="margin: 0px auto;position: relative;left: 50%;transform: translateX(-0.25rem);"
+          />
+          <div
+            class="myCourseList"
+            v-if="user_info.marketable && tbsIndex == 0 && !showLoad"
+          >
+            <courseList
+              :dataList="courseClass.proCourse.courseList"
+              :showNum="1"
+              :fixedTitle="courseClass.proCourse.title"
+            ></courseList>
+          </div>
+          <div class="myCourseList" v-if="tbsIndex == 1 && !showLoad">
+            <courseList
+              :dataList="courseClass.learnCourse.courseList"
+              :fixedTitle="courseClass.learnCourse.title"
+              isNoAd
+            ></courseList>
+          </div>
+        </scroller>
+      </div>
+      <van-overlay :show="qrVisible" @click="qrVisible = false">
+        <div class="wrapper">
+          <div class="qrContent">
+            <div class="tit">
+              邀请二维码
+            </div>
+            <div class="canvasImg" ref="canvasImg" v-if="imgEwmUrl == ''">
+              <div class="qrcode-wrap" ref="qrCodeUrl"></div>
+              <div class="btm">
+                <p>邀请朋友成为经销商,并加入你的团队</p>
+              </div>
+            </div>
+            <img :src="imgEwmUrl" v-else>
+          </div>
+        </div>
+      </van-overlay>
+    </div>
+  </template>
+  
+  <script>
+  import Clipboard from "clipboard";
+  import QRCode from "qrcodejs2";
+  import html2canvas from "html2canvas";
+  import Canvas2Image from "./utils/convas2Images";
+  import courseList from "./components/courseList.vue";
+  import {setDocumentTitle} from '../../components/vueHashCalendar/utils/util'
+  import {isWeChatMobile,isWeChatPC,isWeChat} from './utils'
+  import {
+    getWxApiToken,
+    getUSerInfo,
+    getDealerCourseList,
+    getUserCourseList
+  } from "./api";
+  export default {
+    name: "courseHome",
+    components: {
+      courseList
+    },
+    data() {
+      return {
+        defaultImgUrl:require('../../assets/images/courseUser.png'),
+        showLoad: false,
+        tbsIndex: 0,
+        clipboard: null,
+        qrVisible: false,
+        qrcode: null,
+        qrcodeStatus: false,
+        imgEwmUrl:'',
+        isAndroid: this.$getCache("isAndroid"),
+        user_info: {
+          imgUrl: "",
+          id: "0",
+          name: "用户名",
+          mobile: "0",
+          marketable: false
+        },
+        page: {
+          cur: 1,
+          size: 10,
+          total: 0
+        },
+        courseClass: {
+          proCourse: {
+            title: "我推广的课程",
+            total: 0,
+            courseList: []
+          },
+          learnCourse: {
+            title: "我学习的课程",
+            total: 0,
+            courseList: []
+          }
+        },
+        wxId: "11770"
+      };
+    },
+    created() {
+      this.init();
+      console.log(isWeChat()?isWeChatMobile()?'手机微信':isWeChatPC()?'电脑微信':'无法判断':'不是微信')
+    },
+    watch: {
+      $route(to) {
+        if (to.path == "/courseHome") {
+          this.init();
+        }
+      }
+    },
+    methods: {
+      // 推广/学习标签切换
+      selectTbs(i) {
+        if (this.user_info.marketable) {
+          if (i == 0 && this.tbsIndex != 0) {
+            this.tbsIndex = 0;
+            this.showLoad = true;
+            setTimeout(() => {
+              this.getDealerCourseList();
+            }, 1000);
+          } else if (i == 1 && this.tbsIndex != 1) {
+            this.tbsIndex = 1;
+            this.showLoad = true;
+            setTimeout(() => {
+              this.getUserCourseList();
+            }, 1000);
+          }
+        }
+      },
+      //查看名额变动明细
+      toMoreUrl() {
+        // this.$router.push(`/course/adlist`);
+        this.$router.push(`/course/limitChange`);
+      },
+      // 清楚本地存储/测试用
+      changeUSer() {
+        localStorage.clear();
+        this.getUerInfo(this.wxId);
+      },
+      // 获取指定用户信息/测试用
+      getUerInfo(wxid) {
+        getWxApiToken(wxid).then(token => {
+          getUSerInfo(token).then(res => {
+            this.user_info = JSON.parse(localStorage.getItem("wx_user_info"));
+            if (this.user_info.marketable) {
+              getDealerCourseList();
+            } else if (!this.user_info.marketable) {
+              this.tbsIndex = 1;
+            }
+            getUserCourseList();
+          });
+        });
+      },
+      //获取用户数据
+      init() {
+        setDocumentTitle('首页')
+        this.user_info = JSON.parse(localStorage.getItem("wx_user_info"));
+        if (this.user_info.marketable) {
+          this.getDealerCourseList();
+        } else if (!this.user_info.marketable) {
+          this.tbsIndex = 1;
+        }
+        this.getUserCourseList();
+      },
+      //获取经销推广课程列表
+      getDealerCourseList(done) {
+        getDealerCourseList().then(res => {
+          this.courseClass.proCourse.total = res.total;
+          this.courseClass.proCourse.courseList = res.list;
+          this.showLoad = false;
+          if (done) done();
+        });
+      },
+      //获取用户消费的课程列表
+      getUserCourseList(done) {
+        getUserCourseList().then(res => {
+          this.courseClass.learnCourse.total = res.total;
+          let list = [];
+          res.list.forEach(item => {
+            let data = {
+              subjectName: item.name,
+              subjectId: item.id,
+              subjectPrice: item.price,
+              subjectThumb: item.thumb,
+              subjectEnable: item.enable,
+              sectionsNum: item.sectionsNum
+            };
+            list.push(data);
+          });
+          this.courseClass.learnCourse.courseList = list;
+          this.showLoad = false;
+          if (done) done();
+        });
+      },
+      // 打开二维码
+      qropen() {
+        this.qrVisible = true;
+        this.$nextTick(() => {
+          this.creatQrCode();
+        });
+      },
+      // 创建二维码
+      creatQrCode() {
+        if (!this.qrcodeStatus) {
+          console.log(
+            `${window.location.href.split("#")[0]}#/courseLogin?pid=${
+              JSON.parse(localStorage.getItem("wx_user_info")).id
+            }`
+          );
+          this.qrcode = new QRCode(this.$refs.qrCodeUrl, {
+            text: `${window.location.href.split("#")[0]}#/courseLogin?pid=${
+              JSON.parse(localStorage.getItem("wx_user_info")).id
+            }`, // 需要转换为二维码的内容
+            width: 200,
+            height: 200,
+            colorDark: "#000000",
+            colorLight: "#ffffff",
+            correctLevel: QRCode.CorrectLevel.H
+          });
+          this.qrcodeStatus = true;
+          this.createImg();
+        }
+      },
+      createImg() {
+        const vm = this;
+       const domObj = document.getElementById("posterHtml");
+  
+       var width = document.documentElement.clientWidth;
+       var height = document.documentElement.clientHeight;
+       var canvas = document.createElement("canvas");
+       var scale = 2;
+  
+       canvas.width = width * scale;
+       canvas.height = height * scale;
+       canvas.getContext("2d").scale(scale, scale);
+  
+       var opts = {
+         scale: scale,
+         canvas: canvas,
+         logging: true,
+         width: width,
+         height: height,
+         useCORS: true,
+         allowTaint: false,
+         logging: false,
+         letterRendering: true,
+  
+       };
+  
+  
+  
+        let that = this
+        var opts = {
+          useCORS: true, //支持图片跨域
+          allowTaint: false, //这个属性和useCORS不能同时为true哦
+          logging: false,
+          letterRendering: true,
+        };
+        html2canvas(this.$refs.canvasImg, opts) //传入你想生成图片的dom
+          .then(function (canvas) {
+            var img = Canvas2Image.convertToImage(
+              canvas,
+              canvas.width,
+              canvas.height
+            );
+            img.style.width = "200px";
+            img.style.height = "250px";
+            var url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
+            that.imgEwmUrl = url
+          });
+      },
+      //复制剪切板
+      copyLink(event) {
+        let that = this;
+        //这里是复制目标的类名
+        that.clipboard = new Clipboard(event, {
+          text: function(trigger) {
+            return trigger.getAttribute("aria-label");
+          }
+        });
+        console.log(that.clipboard)
+        that.clipboard.on("success", function(e) {
+          e.clearSelection(); //清除选中的文字的选择状态
+          that.$toast.success("ID复制成功~");
+        });
+  
+        that.clipboard.on("error", function(e) {
+          console.error(e);
+        });
+      },
+      //跳转内页
+      toUrl(url, params) {
+        this.$router.push({
+          path: url
+        });
+      }
+    }
+  };
+  </script>
+  <style scoped lang="scss">
+  @import "../../assets/iconfont.css";
+  * {
+    margin: 0;
+    padding: 0;
+  }
+  img {
+    display: block;
+  }
+  .curPage {
+    height: 100%;
+    position: relative !important;
+    padding-top: 0.4rem;
+    background: #f3f2ee;
+    background: linear-gradient(90deg, #f3f2ee, #e7eff9);
+    .userInfo {
+      padding: 0.24rem 0.32rem 0.12rem;
+      .userImage {
+        display: flex;
+        align-items: center;
+        flex: 1;
+        .info {
+          display: flex;
+          flex-direction: column;
+          justify-content: center;
+          margin-left: 0.2rem;
+          span {
+            font-size: 0.32rem;
+            font-weight: 600;
+            color: #000;
+            line-height: 2;
+            display: block;
+          }
+          p {
+            font-size: 0.22rem;
+            color: #222;
+            line-height: 1;
+            display: block;
+            i {
+              font-size: 0.22rem;
+              color: #222;
+              line-height: 1;
+            }
+          }
+        }
+      }
+      .user_leave {
+        padding: 0.05rem 0.3rem;
+        font-size: 0.26rem;
+        font-weight: 550;
+        color: #a66666;
+        border: 1px solid #c9c3c0;
+        border-radius: 0.1rem;
+        line-height: 1.5;
+      }
+    }
+    .user_tabs {
+      padding: 0 0.2rem;
+      margin-top: 0.15rem;
+      .tabs_content {
+        box-sizing: border-box;
+        height: 1.5rem;
+        padding: 0.1rem 0;
+        display: flex;
+        justify-content: space-around;
+        border-radius: 0.1rem;
+        background: #fff;
+        .tabsLi {
+          // flex: 1;
+          display: flex;
+          flex-direction: column;
+          justify-content: center;
+          align-items: center;
+          span {
+            font-size: 0.24rem;
+            color: #333;
+            line-height: 0.3rem;
+          }
+        }
+      }
+    }
+    .user_course_tabs {
+      margin: 0.15rem 0.2rem 0;
+      display: flex;
+      justify-content: space-between;
+      align-items: center;
+      background-color: #fff;
+      border-radius: .1rem;
+      overflow: hidden;
+      .ctbsL {
+        width: 2rem;
+        display: flex;
+        align-items: center;
+      }
+      .tbsL {
+        width: 60%;
+        display: flex;
+        align-items: center;
+        .tbsi {
+          padding: 0 0.15rem;
+          border-radius: 0.25rem;
+          border: 0.02rem solid #999;
+          font-size: 0.24rem;
+          color: #444;
+          line-height: 0.4rem;
+          text-align: center;
+          margin-right: 0.2rem;
+          &.active {
+            border: 1px solid rgb(22, 132, 252);
+            background-color: rgba(38, 162, 255, 0.1);
+            color: rgb(22, 132, 252);
+          }
+        }
+      }
+      .tbsR {
+        display: flex;
+        align-items: center;
+        margin-right: .2rem;
+        span {
+          font-size: 0.24rem;
+          color: #333;
+          line-height: 0.4rem;
+        }
+      }
+    }
+    .courScroll {
+      height: calc(100vh - 2.75rem) !important;
+      position: relative;
+      .cScroll {
+        height: 100%;
+        position: relative !important;
+      }
+      .myCourseList {
+        &:nth-child(2) {
+          padding-bottom: 0.4rem;
+        }
+        padding: 0 0.2rem;
+        // margin-top: 0.2rem;
+      }
+    }
+    .wrapper {
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      height: 100vh;
+      .qrContent {
+        width: 70%;
+        border-radius: 0.2rem;
+        overflow: hidden;
+        background-color: #FFF;
+        img{
+          width: 100%;
+        }
+        .canvasImg{
+          width: 100%;
+        }
+        .btm{
+          font-size: .23rem;
+          color: #666;
+          line-height: .6rem;
+          text-align: center;
+          border: 0;
+        }
+        .tit {
+          position: relative;
+          width: 100%;
+          text-align: center;
+          font-size: 0.3rem;
+          color: #333;
+          line-height: 0.8rem;
+          &::after {
+            content: "X";
+            position: absolute;
+            right: 0.2rem;
+            top: 0.2rem;
+            font-size: 0.3rem;
+            line-height: 0.3rem;
+          }
+        }
+        .qrcode-wrap {
+          padding: 0.2rem .2rem 0;
+          background-color: #fff;
+          text-align: center;
+          display: flex;
+          justify-content: center;
+        }
+      }
+    }
+  }
+  /deep/ .van-search .van-cell {
+    padding: 0.1rem 0.16rem 0.1rem 0.16rem;
+  }
+  /deep/ .van-tabs--line .van-tabs__wrap{
+    height: .68rem;
+  }
+  /deep/ .van-tab--active{
+    font-weight: 600;
+  }
+  </style>
+  

+ 266 - 0
src/view/course/utils/convas2Images.js

@@ -0,0 +1,266 @@
+/**
+ * covert canvas to image
+ * and save the image file
+ */
+ 
+var Canvas2Image = function () {
+ 
+	// check if support sth.
+	var $support = function () {
+		var canvas = document.createElement('canvas'),
+			ctx = canvas.getContext('2d');
+ 
+		return {
+			canvas: !!ctx,
+			imageData: !!ctx.getImageData,
+			dataURL: !!canvas.toDataURL,
+			btoa: !!window.btoa
+		};
+	}();
+ 
+	var downloadMime = 'image/octet-stream';
+ 
+	function scaleCanvas (canvas, width, height) {
+		var w = canvas.width,
+			h = canvas.height;
+		if (width == undefined) {
+			width = w;
+		}
+		if (height == undefined) {
+			height = h;
+		}
+ 
+		var retCanvas = document.createElement('canvas');
+		var retCtx = retCanvas.getContext('2d');
+		retCanvas.width = width;
+		retCanvas.height = height;
+		retCtx.drawImage(canvas, 0, 0, w, h, 0, 0, width, height);
+		return retCanvas;
+	}
+ 
+	function getDataURL (canvas, type, width, height) {
+		canvas = scaleCanvas(canvas, width, height);
+		return canvas.toDataURL(type);
+	}
+ 
+	function saveFile (strData) {
+		document.location.href = strData;
+	}
+ 
+	function genImage(strData) {
+		var img = document.createElement('img');
+		img.src = strData;
+		return img;
+	}
+	function fixType (type) {
+		type = type.toLowerCase().replace(/jpg/i, 'jpeg');
+		var r = type.match(/png|jpeg|bmp|gif/)[0];
+		return 'image/' + r;
+	}
+	function encodeData (data) {
+		if (!window.btoa) { throw 'btoa undefined' }
+		var str = '';
+		if (typeof data == 'string') {
+			str = data;
+		} else {
+			for (var i = 0; i < data.length; i ++) {
+				str += String.fromCharCode(data[i]);
+			}
+		}
+ 
+		return btoa(str);
+	}
+	function getImageData (canvas) {
+		var w = canvas.width,
+			h = canvas.height;
+		return canvas.getContext('2d').getImageData(0, 0, w, h);
+	}
+	function makeURI (strData, type) {
+		return 'data:' + type + ';base64,' + strData;
+	}
+ 
+ 
+	/**
+	 * create bitmap image
+	 * 按照规则生成图片响应头和响应体
+	 */
+	var genBitmapImage = function (oData) {
+ 
+		//
+		// BITMAPFILEHEADER: http://msdn.microsoft.com/en-us/library/windows/desktop/dd183374(v=vs.85).aspx
+		// BITMAPINFOHEADER: http://msdn.microsoft.com/en-us/library/dd183376.aspx
+		//
+ 
+		var biWidth  = oData.width;
+		var biHeight	= oData.height;
+		var biSizeImage = biWidth * biHeight * 3;
+		var bfSize  = biSizeImage + 54; // total header size = 54 bytes
+ 
+		//
+		//  typedef struct tagBITMAPFILEHEADER {
+		//  	WORD bfType;
+		//  	DWORD bfSize;
+		//  	WORD bfReserved1;
+		//  	WORD bfReserved2;
+		//  	DWORD bfOffBits;
+		//  } BITMAPFILEHEADER;
+		//
+		var BITMAPFILEHEADER = [
+			// WORD bfType -- The file type signature; must be "BM"
+			0x42, 0x4D,
+			// DWORD bfSize -- The size, in bytes, of the bitmap file
+			bfSize & 0xff, bfSize >> 8 & 0xff, bfSize >> 16 & 0xff, bfSize >> 24 & 0xff,
+			// WORD bfReserved1 -- Reserved; must be zero
+			0, 0,
+			// WORD bfReserved2 -- Reserved; must be zero
+			0, 0,
+			// DWORD bfOffBits -- The offset, in bytes, from the beginning of the BITMAPFILEHEADER structure to the bitmap bits.
+			54, 0, 0, 0
+		];
+ 
+		//
+		//  typedef struct tagBITMAPINFOHEADER {
+		//  	DWORD biSize;
+		//  	LONG  biWidth;
+		//  	LONG  biHeight;
+		//  	WORD  biPlanes;
+		//  	WORD  biBitCount;
+		//  	DWORD biCompression;
+		//  	DWORD biSizeImage;
+		//  	LONG  biXPelsPerMeter;
+		//  	LONG  biYPelsPerMeter;
+		//  	DWORD biClrUsed;
+		//  	DWORD biClrImportant;
+		//  } BITMAPINFOHEADER, *PBITMAPINFOHEADER;
+		//
+		var BITMAPINFOHEADER = [
+			// DWORD biSize -- The number of bytes required by the structure
+			40, 0, 0, 0,
+			// LONG biWidth -- The width of the bitmap, in pixels
+			biWidth & 0xff, biWidth >> 8 & 0xff, biWidth >> 16 & 0xff, biWidth >> 24 & 0xff,
+			// LONG biHeight -- The height of the bitmap, in pixels
+			biHeight & 0xff, biHeight >> 8  & 0xff, biHeight >> 16 & 0xff, biHeight >> 24 & 0xff,
+			// WORD biPlanes -- The number of planes for the target device. This value must be set to 1
+			1, 0,
+			// WORD biBitCount -- The number of bits-per-pixel, 24 bits-per-pixel -- the bitmap
+			// has a maximum of 2^24 colors (16777216, Truecolor)
+			24, 0,
+			// DWORD biCompression -- The type of compression, BI_RGB (code 0) -- uncompressed
+			0, 0, 0, 0,
+			// DWORD biSizeImage -- The size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps
+			biSizeImage & 0xff, biSizeImage >> 8 & 0xff, biSizeImage >> 16 & 0xff, biSizeImage >> 24 & 0xff,
+			// LONG biXPelsPerMeter, unused
+			0,0,0,0,
+			// LONG biYPelsPerMeter, unused
+			0,0,0,0,
+			// DWORD biClrUsed, the number of color indexes of palette, unused
+			0,0,0,0,
+			// DWORD biClrImportant, unused
+			0,0,0,0
+		];
+ 
+		var iPadding = (4 - ((biWidth * 3) % 4)) % 4;
+ 
+		var aImgData = oData.data;
+ 
+		var strPixelData = '';
+		var biWidth4 = biWidth<<2;
+		var y = biHeight;
+		var fromCharCode = String.fromCharCode;
+ 
+		do {
+			var iOffsetY = biWidth4*(y-1);
+			var strPixelRow = '';
+			for (var x = 0; x < biWidth; x++) {
+				var iOffsetX = x<<2;
+				strPixelRow += fromCharCode(aImgData[iOffsetY+iOffsetX+2]) +
+							   fromCharCode(aImgData[iOffsetY+iOffsetX+1]) +
+							   fromCharCode(aImgData[iOffsetY+iOffsetX]);
+			}
+ 
+			for (var c = 0; c < iPadding; c++) {
+				strPixelRow += String.fromCharCode(0);
+			}
+ 
+			strPixelData += strPixelRow;
+		} while (--y);
+ 
+		var strEncoded = encodeData(BITMAPFILEHEADER.concat(BITMAPINFOHEADER)) + encodeData(strPixelData);
+ 
+		return strEncoded;
+	};
+ 
+	/**
+	 * saveAsImage
+	 * @param canvasElement
+	 * @param {String} image type
+	 * @param {Number} [optional] png width
+	 * @param {Number} [optional] png height
+	 */
+	var saveAsImage = function (canvas, width, height, type) {
+		if ($support.canvas && $support.dataURL) {
+			if (typeof canvas == "string") { canvas = document.getElementById(canvas); }
+			if (type == undefined) { type = 'png'; }
+			type = fixType(type);
+			if (/bmp/.test(type)) {
+				var data = getImageData(scaleCanvas(canvas, width, height));
+				var strData = genBitmapImage(data);
+				saveFile(makeURI(strData, downloadMime));
+			} else {
+				var strData = getDataURL(canvas, type, width, height);
+				saveFile(strData.replace(type, downloadMime));
+			}
+		}
+	};
+ 
+	var convertToImage = function (canvas, width, height, type) {
+		if ($support.canvas && $support.dataURL) {
+			if (typeof canvas == "string") { canvas = document.getElementById(canvas); }
+			if (type == undefined) { type = 'png'; }
+			type = fixType(type);
+ 
+			if (/bmp/.test(type)) {
+				var data = getImageData(scaleCanvas(canvas, width, height));
+				var strData = genBitmapImage(data);
+				return genImage(makeURI(strData, 'image/bmp'));
+			} else {
+				var strData = getDataURL(canvas, type, width, height);
+				return genImage(strData);
+			}
+		}
+	};
+ 
+ 
+ 
+	return {
+		saveAsImage: saveAsImage,
+		saveAsPNG: function (canvas, width, height) {
+			return saveAsImage(canvas, width, height, 'png');
+		},
+		saveAsJPEG: function (canvas, width, height) {
+			return saveAsImage(canvas, width, height, 'jpeg');
+		},
+		saveAsGIF: function (canvas, width, height) {
+			return saveAsImage(canvas, width, height, 'gif');
+		},
+		saveAsBMP: function (canvas, width, height) {
+			return saveAsImage(canvas, width, height, 'bmp');
+		},
+ 
+		convertToImage: convertToImage,
+		convertToPNG: function (canvas, width, height) {
+			return convertToImage(canvas, width, height, 'png');
+		},
+		convertToJPEG: function (canvas, width, height) {
+			return convertToImage(canvas, width, height, 'jpeg');
+		},
+		convertToGIF: function (canvas, width, height) {
+			return convertToImage(canvas, width, height, 'gif');
+		},
+		convertToBMP: function (canvas, width, height) {
+			return convertToImage(canvas, width, height, 'bmp');
+		}
+	};
+ 
+}();
+export default Canvas2Image;