├── README.md └── una2 ├── app.js ├── app.json ├── app.wxss ├── images ├── cat.jpeg ├── img1.jpg ├── img5.jpg ├── one.png ├── one_normal.png ├── three.png ├── three_normal.png ├── two.png └── two_normal.png ├── pages ├── allEffect │ ├── allEffect.js │ ├── allEffect.json │ ├── allEffect.wxml │ └── allEffect.wxss ├── avatarUpload │ ├── index │ │ ├── draw.js │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ └── second │ │ ├── second.js │ │ ├── second.json │ │ ├── second.wxml │ │ └── second.wxss ├── index │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss ├── picture │ ├── picture.js │ ├── picture.json │ ├── picture.wxml │ └── picture.wxss ├── style │ └── common.wxss ├── upload │ ├── upload.js │ ├── upload.json │ ├── upload.wxml │ └── upload.wxss └── we-cropper │ ├── we-cropper.js │ └── we-cropper.wxml ├── project.config.json └── utils └── util.js /README.md: -------------------------------------------------------------------------------- 1 | # Xmxcx 2 | 海报图片处理 3 | -------------------------------------------------------------------------------- /una2/app.js: -------------------------------------------------------------------------------- 1 | //app.js 2 | 3 | App({ 4 | onLaunch: function () { 5 | }, 6 | globalData:{ 7 | userInfo:null, 8 | imgArr : [ 9 | { img: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg', u: "u uone", url: "../avatarUpload/index/index" }, 10 | { img: 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg', u: "u utwo", url: "../avatarUpload/second/second" } 11 | ], 12 | templateData:{} 13 | } 14 | }) -------------------------------------------------------------------------------- /una2/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages":[ 3 | 4 | "pages/index/index", 5 | "pages/avatarUpload/index/index", 6 | "pages/avatarUpload/second/second", 7 | "pages/picture/picture", 8 | 9 | "pages/upload/upload", 10 | "pages/allEffect/allEffect" 11 | ], 12 | "window":{ 13 | "backgroundTextStyle":"dark", 14 | "navigationBarBackgroundColor": "#000", 15 | "navigationBarTitleText": "海报", 16 | "navigationBarTextStyle":"white" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /una2/app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | .container { 3 | /* height: 100%; 4 | display: flex; 5 | flex-direction: column; 6 | align-items: center; 7 | justify-content: space-between; 8 | padding: 200rpx 0; 9 | box-sizing: border-box; */ 10 | } 11 | page{ 12 | -webkit-user-select: none; 13 | user-select: none; 14 | width: 100%; 15 | height: 100%; 16 | background-color: #f8f8f8; 17 | font-family: Arial, Helvetica, sans-serif; 18 | overflow-x: hidden; 19 | } 20 | 21 | .flex{ 22 | display: flex; 23 | justify-content: center; 24 | align-items: center; 25 | } 26 | .none{ 27 | display: none 28 | } -------------------------------------------------------------------------------- /una2/images/cat.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/cat.jpeg -------------------------------------------------------------------------------- /una2/images/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/img1.jpg -------------------------------------------------------------------------------- /una2/images/img5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/img5.jpg -------------------------------------------------------------------------------- /una2/images/one.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/one.png -------------------------------------------------------------------------------- /una2/images/one_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/one_normal.png -------------------------------------------------------------------------------- /una2/images/three.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/three.png -------------------------------------------------------------------------------- /una2/images/three_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/three_normal.png -------------------------------------------------------------------------------- /una2/images/two.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/two.png -------------------------------------------------------------------------------- /una2/images/two_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnaBella/Xmxcx/64612fa3d223691c13bc163ce74da40979693ce9/una2/images/two_normal.png -------------------------------------------------------------------------------- /una2/pages/allEffect/allEffect.js: -------------------------------------------------------------------------------- 1 | // pages/allEffect/allEffect.js 2 | Page({ 3 | data: { 4 | saturate: 170, 5 | brightness: 110, 6 | contrast: 70 7 | }, 8 | baohedu: function (e) { 9 | var self = this; 10 | self.setData({ 11 | saturate: e.detail.value 12 | }); 13 | }, 14 | liangdu: function (e) { 15 | var self = this; 16 | self.setData({ 17 | brightness: e.detail.value 18 | }); 19 | }, 20 | duibidu: function (e) { 21 | var self = this; 22 | self.setData({ 23 | contrast: e.detail.value 24 | }); 25 | } 26 | }) -------------------------------------------------------------------------------- /una2/pages/allEffect/allEffect.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /una2/pages/allEffect/allEffect.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 饱和度 4 | 5 | 亮度 6 | 7 | 对比度 8 | 9 | 10 | -------------------------------------------------------------------------------- /una2/pages/allEffect/allEffect.wxss: -------------------------------------------------------------------------------- 1 | /* pages/allEffect/allEffect.wxss */ -------------------------------------------------------------------------------- /una2/pages/avatarUpload/index/draw.js: -------------------------------------------------------------------------------- 1 | var ctx = wx.createCanvasContext('myCanvas'); 2 | var bg_w; 3 | var bg_h; 4 | var ratio; 5 | 6 | wx.getSystemInfo({ 7 | success: function(res) { 8 | console.log(res); 9 | ratio = res.pixelRatio; 10 | bg_w = res.windowWidth; 11 | bg_h = res.windowHeight 12 | }, 13 | }) 14 | 15 | 16 | function draw(){ 17 | ctx.drawImage(bg, 0, 0, bg_w, bg_h); 18 | } 19 | module.exports = { 20 | draw: draw 21 | } 22 | -------------------------------------------------------------------------------- /una2/pages/avatarUpload/index/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by sail on 2017/4/14. 3 | */ 4 | var draw = require('./draw.js'); 5 | const app = getApp(); 6 | Page({ 7 | data: { 8 | srcsss: { 9 | '0': { 10 | 'src': '' 11 | } 12 | }, 13 | src: '', 14 | bg:'', 15 | //饱和度 / 亮度 / 对比度 / 灰度 / 陈旧度(褐色) 16 | saturate: 100, 17 | brightness: 100, 18 | contrast: 100, 19 | grayscale: 0, 20 | sepia: 0, 21 | pixelRatio : 0, 22 | windowWidth : 0, 23 | windowHeight : 0, 24 | genateBtnShow: 'none', 25 | containerShow : '', 26 | canvasShow : '', 27 | targetImg :{ 28 | width:93, 29 | height:93, 30 | left: 140, 31 | top:215, 32 | src : '' 33 | } 34 | }, 35 | //输入框 36 | bindTextAreaBlur: function (e) { 37 | console.log(e.detail.value) 38 | }, 39 | 40 | tofilter: function (option) { 41 | wx.navigateTo({ 42 | url: '../../../pages/picture/picture?datai=' + option.currentTarget.dataset.i 43 | }) 44 | }, 45 | 46 | 47 | onLoad : function (option) { 48 | let avatar, index; 49 | if (option.avatar !== undefined) { avatar = option.avatar }; 50 | 51 | if (avatar !== undefined) { 52 | this.setData({ 53 | src: avatar 54 | }) 55 | } 56 | 57 | 58 | if (option.index !== undefined) { 59 | index = 1 * (option.index); 60 | //全局变量方式 61 | var imgArr = app.globalData.imgArr; 62 | this.setData({ 63 | bg: imgArr[index].img 64 | }); 65 | } 66 | }, 67 | onShow : function(){ 68 | var _this = this; 69 | this.data.src = this.data.srcsss['0'].src; 70 | if (this.data.src !== ''){ 71 | //显示生成图片按钮 72 | this.setData({ 73 | genateBtnShow : '' 74 | }); 75 | 76 | //设置设备参数 77 | wx.getSystemInfo({ 78 | success: function (res) { 79 | _this.setData({ 80 | pixelRatio: res.pixelRatio, 81 | windowWidth: res.windowWidth, 82 | windowHeight: res.windowHeight 83 | }) 84 | } 85 | }); 86 | } 87 | }, 88 | generatePic : function(e){ 89 | var ctx = wx.createCanvasContext('canvas'); 90 | var _this = this; 91 | var data = this.data; 92 | var bg_w = data.windowWidth * data.pixelRatio; 93 | var bg_h = data.windowHeight * data.pixelRatio; 94 | var head_w = data.targetImg.width * data.pixelRatio; 95 | var head_h = data.targetImg.height * data.pixelRatio; 96 | var head_left = data.targetImg.left * data.pixelRatio; 97 | var head_top = data.targetImg.top * data.pixelRatio; 98 | 99 | wx.showLoading({ 100 | title: '生成中...', 101 | }) 102 | //将图片保存到本地(canvas绘制线上图片时,必须先下载到本地,真机不显示) 103 | wx.downloadFile({ 104 | url: data.bg, 105 | success: function (res) { 106 | if (res.statusCode === 200) { 107 | wx.saveFile({ 108 | tempFilePath: res.tempFilePath, //下载后的图片临时地址 109 | success: function (res) { 110 | var savedFilePath = res.savedFilePath 111 | //头像,描述生成海报 112 | //1.绘制背景 113 | ctx.drawImage(savedFilePath, 0, 0, bg_w, bg_h); 114 | ctx.draw(true,function(){ 115 | //------------------------------------------------------------------- 116 | //2.绘制头像 117 | ctx.drawImage(data.src, head_left, head_top, head_w, head_h); 118 | ctx.draw(true, function () { 119 | //3.canvas生成图片 120 | wx.canvasToTempFilePath({ 121 | x: 0, 122 | y: 0, 123 | width: bg_w, 124 | height: bg_h, 125 | destWidth: bg_w, 126 | destHeight: bg_h, 127 | canvasId: 'canvas', 128 | success: function (res) { 129 | _this.setData({ 130 | containerShow: 'none', 131 | canvasShow: 'none', 132 | genateBtnShow: 'none', 133 | targetImg: { 134 | src: res.tempFilePath 135 | } 136 | }); 137 | wx.hideLoading(); 138 | //4.保存到相册 139 | if (wx.saveImageToPhotosAlbum) { 140 | console.log(res.tempFilePath); 141 | wx.saveImageToPhotosAlbum({ 142 | filePath: res.tempFilePath, 143 | success: function (res) { 144 | console.log(res); 145 | //Toast 146 | wx.showToast({ 147 | title: '保存到相册', 148 | icon: 'success', 149 | duration: 2000 150 | }); 151 | }, 152 | fail: function (res) { 153 | console.log(res) 154 | console.log('fail') 155 | } 156 | }); 157 | } else { 158 | wx.showModal({ 159 | title: '提示', 160 | content: '预览长按保存' 161 | }) 162 | } 163 | 164 | } 165 | }); 166 | }); 167 | 168 | }); 169 | }, 170 | fail: function () { 171 | console.log("保存图片失败") 172 | } 173 | }) 174 | } 175 | } 176 | }); 177 | 178 | }, 179 | /** 180 | * 预览图片 181 | */ 182 | previewImage: function (e) { 183 | var current = e.target.dataset.src; 184 | wx.previewImage({ 185 | current: current, // 当前显示图片的http链接 186 | urls: [this.data.targetImg.src] // 需要预览的图片http链接列表 187 | }) 188 | } 189 | }) 190 | -------------------------------------------------------------------------------- /una2/pages/avatarUpload/index/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "backgroundTextStyle": "dark", 3 | "navigationBarBackgroundColor": "#000", 4 | "navigationBarTitleText": "海报模板", 5 | "navigationBarTextStyle": "#fff" 6 | } -------------------------------------------------------------------------------- /una2/pages/avatarUpload/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | click me 6 | 7 | 8 |