微信小程序-图片清晰度修复

微信小程序端

登录界面

.wxml

<view class="page-body">
  <text>手机号</text>
  <input bindinput="bindPhone" type="number" maxlength="11" placeholder="最大输入长度为11" />
  <text>密码<text bindtap="message">点击获取验证码</text></text>
  <input bindinput="bindCode" password type="text" placeholder="请输入密码" />
</view>
<button bindtap="login">登录</button>

在这里插入图片描述

.js

// pages/login/login.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isTrue:false,
    phone:"",
    code:""
  },
  bindPhone(e){
    this.setData({phone:e.detail.value});
  },
  bindCode(e){
    this.setData({code:e.detail.value});
  },
  message(){
    if (this.data.phone.lenth!=11){
      wx.showToast({
        title: '长度错误',
        icon:"none"
      })
      return ;
    }
    var reg=/^(1[3|4|5|6|7|8|9])\d{9}$/;
    if(!reg.test(this.data.phone)){
      wx.showToast({
        title: '格式错误',
        icon:"none"
      })
      return ;
    }
    wx.request({
      url: 'http://(ip:端口)/message',
      data: {phone:this.data.phone},
      method: "POST",
      success:(res)=>{
        console.log(res);
      }
    })


  },
  login:function(){
    var that=this;
    wx.request({
      url: 'http://(ip:端口)/login',
      data: {phone:this.data.phone,code:this.data.code},
      method: "POST",
      success:(result) => {
        that.setData({isTrue:result.data})
        if( that.data.isTrue=="True")
          wx.navigateTo({
            url: '/pages/uploader/uploader',
          })
          else{
            wx.showModal({
              cancelColor: 'cancelColor',
              title:"密码错误或账号不存在"
            })
            // wx.showToast({
            //   title: '密码错误或账号不存在',
            //   icon:"error"
            // })
          }
      },
      fail: (res) => {},
      complete: (res) => {},
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  }
})
后端服务接口
@app.route('/login', methods=['POST'])
def  weixin():
    phone=request.get_json()['phone']
    code=request.get_json()['code']
    conn=pymysql.connect(local_infile='127.0.0.1',user='root',password='Hello')
    cursor=conn.cursor()
    cursor.execute('select * from designdb.userinfo;')
    result=cursor.fetchall()
    print(phone,code)
    cursor.close()
    conn.commit()
    conn.close()
    for some in result:
        print(some[0],some[1])
        if phone==some[0] and code==some[1]:
            print('yes')
            return 'True'
        print('no')
    return 'False'

这里采用数据库存储信息的方式,在服务端验证账号密码

数据库组成

在这里插入图片描述

uploader页面

.wxml

<button type="warn" bindtap="uploadimg">上传图片</button>
<button bindtap="pretectpic">开始运行</button>
<view class="container" bindtap="viewimages">
  <image wx:for="{{imagelist}}" src="{{item}}"></image>
</view>
<image src="{{imgs}}" ></image>

.js

// pages/goods/goods.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    datalist:["goods1","goods2","goods3","goods4","goods5"],
    userinfo:{name:"xiaoming",
      age:18},
    // imagelist:["/images/icon1.png","/images/icon2.png","/images/icon3.png","/images/icon1.png",]
    imagelist:"",
    imgs:""
  },
  uploadimg:function(){
    
    var that=this;
    wx.chooseImage({
      count: 1,
      sizeType:["original","compressed"],
      sourceType:["album","camera"],
      success:function(res){
        const tempFilePaths=res.tempFilePaths[0];
        console.log(tempFilePaths)
        that.setData({imagelist:res.tempFilePaths})
        wx.cloud.uploadFile({
          cloudPath:'storage/pic3',
          filePath:tempFilePaths
        })
        wx.showModal({
          cancelColor: 'cancelColor',
          title:"上传成功"
        })
      },fail(res){
        console.log("fail"+res);
      },complete(res){
        console.log("complete"+res);
      }
    })
  },
  pretectpic(){
    var that =this;

    wx.request({
      url: 'http://(ip:端口)/uploader',
      data: {domin:"(图片在云存储的位置)"},
      method: "POST",
      success: (res) => {
        if (res.data) {
          base64Data = wx.arrayBufferToBase64(wx.base64ToArrayBuffer(res.data));
     /// 拼接请求头,data格式可以为image/png或者image/jpeg等,看需求
     const base64ImgUrl = "data:image/png;base64," + base64Data;
     /// 刷新数据
      
          that.setData({
             imgs : base64ImgUrl
          })
         
        } 
      }
    })
  },
  viewimages(){
    var that=this;
    wx.previewImage({
      current:"",
      urls: that.data.imagelist
    })
  },
  onLoad(options) {

  }
})
后端接口
@app.route('/uploader',methods=['POST'])
def uploader():
    url=request.get_json()['domin']
    resp = requests.get(url)
    time.sleep(0.5)
    with open('inputs/result.jpg', mode='wb') as f:
        f.write(resp.content)
        f.close()
    os.system("(待执行的python指令)")
    return return_img_stream('results/result_out.jpg')
推理接口

Real-ESRGAN-master
Real-ESRGAN-master项目地址
使用方法

python后端

利用flask搭建的服务后端

import json
import os
import time

import requests
from flask import Flask
from flask import request
from flask import jsonify
import pymysql
# from flask_cors import CORS
from gevent import pywsgi
# from geventwebsocket.handler import WebSocketHandler
import  queue

app = Flask(__name__)
app.config['DEBUG'] = True

def return_img_stream(img_local_path):
    import base64
    with open(img_local_path, 'rb') as img_f:
        img_stream = img_f.read()
        img_stream = base64.b64encode(img_stream).decode()
    return img_stream

@app.route('/func3',methods=['POST'])
def message():
    url=request.get_json()['domin']
    resp = requests.get(url)
    time.sleep(0.5)
    with open('inputs/result.jpg', mode='wb') as f:
        f.write(resp.content)
        f.close()
    os.system("(待执行的python指令)")
    return return_img_stream('results/result_out.jpg')


@app.route('/login', methods=['POST'])
def  weixin():
    phone=request.get_json()['phone']
    code=request.get_json()['code']
    conn=pymysql.connect(local_infile='127.0.0.1',user='',password='')
    cursor=conn.cursor()
    cursor.execute('select * from designdb.userinfo;')
    result=cursor.fetchall()
    print(phone,code)
    cursor.close()
    conn.commit()
    conn.close()
    for some in result:
        print(some[0],some[1])
        if phone==some[0] and code==some[1]:
            print('yes')
            return 'True'
        print('no')
    return 'False'

if  __name__ == "__main__":
    # app.config['SECRET_KEY'] = '!QAZ2wsx'
    # http_server = pywsgi.WSGIServer(('', 5007), app, keyfile='qiangzhou.key',certfile='qiangzhou.crt', handler_class = WebSocketHandler)
    # http_server.serve_forever()
    app.run("0.0.0.0",port=4000)

实现效果

在这里插入图片描述

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值