All Projects → AfanSama → Easy Canvas

AfanSama / Easy Canvas

Licence: mit
小程序简单绘图,通过 json 方式绘制一张朋友圈分享图

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Easy Canvas

Mp canvas drawer
🚀 微信小程序上canvas绘制图片助手,一个json就制作分享朋友圈图片
Stars: ✭ 1,611 (+1276.92%)
Mutual labels:  xiaochengxu, wxapp, canvas
We Cropper
微信小程序图片裁剪工具
Stars: ✭ 1,972 (+1585.47%)
Mutual labels:  wxapp, canvas
Wxa Comp Canvas Drag
小程序组件-canvas拖拽组件
Stars: ✭ 208 (+77.78%)
Mutual labels:  wxapp, canvas
Wxa Plugin Canvas
小程序海报组件-生成朋友圈分享海报并生成图片
Stars: ✭ 2,692 (+2200.85%)
Mutual labels:  wxapp, canvas
Alembic
⚗️ Functional JSON Parser - Linux Ready 🐧
Stars: ✭ 115 (-1.71%)
Mutual labels:  json
Symfony Jsonapi
JSON API Transformer Bundle for Symfony 2 and Symfony 3
Stars: ✭ 114 (-2.56%)
Mutual labels:  json
Vue Graph
⚡️ Vue components based on the JUI chart available in Vue.js
Stars: ✭ 114 (-2.56%)
Mutual labels:  canvas
Marklogic Data Hub
The MarkLogic Data Hub: documentation ==>
Stars: ✭ 113 (-3.42%)
Mutual labels:  json
Captagent
100% Open-Source Packet Capture Agent for HEP
Stars: ✭ 116 (-0.85%)
Mutual labels:  json
Kafka Connect Spooldir
Kafka Connect connector for reading CSV files into Kafka.
Stars: ✭ 116 (-0.85%)
Mutual labels:  json
Vue Thanos Snap
thanos snap animation by vue
Stars: ✭ 115 (-1.71%)
Mutual labels:  canvas
World Currencies
Currency information in JSON
Stars: ✭ 114 (-2.56%)
Mutual labels:  json
Fleece
A super-fast, compact, JSON-equivalent binary data format
Stars: ✭ 114 (-2.56%)
Mutual labels:  json
Dynamodb Json
DynamoDB json util to load and dump strings of Dynamodb json format to python object and vise-versa
Stars: ✭ 114 (-2.56%)
Mutual labels:  json
Fetch Plus
🐕 Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Stars: ✭ 116 (-0.85%)
Mutual labels:  json
M Mall
🐶 微信小程序-小商城前台(基于 WeUI.wxss、ES6 前端技术开发...)
Stars: ✭ 1,484 (+1168.38%)
Mutual labels:  wxapp
Canvas
Peer-to-peer canvas app for Urbit
Stars: ✭ 114 (-2.56%)
Mutual labels:  canvas
Yunban
fullstack movie & music proj(rebuilding)
Stars: ✭ 116 (-0.85%)
Mutual labels:  canvas
Just Dashboard
📊 📋 Dashboards using YAML or JSON files
Stars: ✭ 1,511 (+1191.45%)
Mutual labels:  json
Mockit
A tool to quickly mock out end points, setup delays and more...
Stars: ✭ 1,534 (+1211.11%)
Mutual labels:  json

抱歉各位,本项目已经停止维护,为了不给您使用造成问题,请仅做参考使用,感谢各位支持

easy-canvas

开发者工具请打开不校验合法域名,真机调试时请打开调试,真机无法绘制多半是微信安全域名的问题。

新增更新图片透明度

新增功能矩形、圆角矩形绘制阴影效果

新增 easy-canvas。之后同步更新。

做微信小程序中最好用的 canvas 绘图组件之一。

当前环境下,大家都非常需要分享到朋友圈这个功能,但是实现起来各有心酸(坑比较多),所以才有了如下的 canvas 绘图工具。

具有如下特性:

  • 简单易用 —— 一个 json 搞定绘制图片
  • 功能全 —— 满足 90% 的使用场景
    • 绘制文本(换行、超出内容省略号、中划线、下划线、文本加粗)
    • 绘制图片
    • 绘制矩形
    • 保存图片
    • 多图绘制
    • 圆形图片
    • 绘制圆角矩形
    • ...
  • 代码量小

体验

git clone https://github.com/AfanSama/easy-canvas

想在手机上使用配置自己的 appid 即可。

编译模式中已经为你配置好比较常用的两种模式:

  • 普通绘制,绘制单张分享图。
  • 多图绘制,连续绘制分享图

使用

  • git clone https://github.com/AfanSama/easy-canvas 到本地

  • components 中的 easy-canvas 拷贝到自己项目下。

  • 在使用页面注册组件

    {
      "usingComponents": {
        "easy-canva": "/components/easy-canva/easy-canva"
      }
    }
    
  • 在页面 **.wxml 文件中加入如下代码

    <easy-canvas painting="{{painting}}" bind:getImage="eventGetImage"/>
    

    painting 是需要传入的 jsongetImage 方法是绘图完成之后的回调函数,在 event.detail 中返回绘制完成的图片地址。

  • 当前栗子中的 painting 简单展示一下。详细配置请看 API

    painting(点击展开)
    painting: {
          width: 375,
          height: 555,
          clear: true,
          views: [{
              type: 'image',
              url: '/images/background.jpg',
              top: 0,
              left: 0,
              width: 375,
              height: 555
            },
            {
              type: 'roundrect',
              background: "#fff",
              top: 57.5,
              left: 88,
              width: 280,
              height: 25,
              radius:10,
              shadowBlur: 10,
              shadowColor: "rgba(255,255,255,.5)"
            },
            {
              type: 'image',
              url: 'https://wx.qlogo.cn/mmhead/Q3auHgzwzM7v6mLlMiblTaIBuq8VYHVBj61wC69r1jfz4wvjicSsMnKg/0',
              top: 27.5,
              left: 29,
              width: 55,
              height: 55,
              borderRadius: true
            },
            {
              type: 'text',
              content: '您的好友【Afan】',
              fontSize: 16,
              color: '#fff',
              textAlign: 'left',
              top: 33,
              left: 96,
              bolder: true
            },
            {
              type: 'text',
              content: '发现一件好货,邀请你一起0元免费拿!',
              fontSize: 15,
              color: '#563D20',
              textAlign: 'left',
              top: 59.5,
              left: 96
            },
            {
              type: 'image',
              url: '/images/pic.jpg',
              top: 136,
              left: 42.5,
              width: 290,
              height: 186,
              opacity:70
            },
            {
              type: 'image',
              url: '/images/qrcode.jpg',
              top: 470,
              left: 85,
              width: 68,
              height: 68,
              borderRadius: true
            },
            {
              type: 'text',
              content: '正品MAC魅可口红礼盒生日唇膏小辣椒Chili西柚情人',
              fontSize: 16,
              lineHeight: 21,
              color: '#fff',
              textAlign: 'left',
              top: 336,
              left: 44,
              width: 287,
              MaxLineNumber: 2,
              breakWord: true,
              bolder: true
            },
            {
              type: 'text',
              content: '¥0.00',
              fontSize: 19,
              color: '#E62004',
              textAlign: 'left',
              top: 387,
              left: 44.5,
              bolder: true
            },
            {
              type: 'text',
              content: '原价:¥138.00',
              fontSize: 13,
              color: '#7E7E8B',
              textAlign: 'left',
              top: 391,
              left: 110,
              textDecoration: 'line-through'
            },
            {
              type: 'text',
              content: '长按识别图中二维码帮我砍个价呗~',
              fontSize: 14,
              color: '#383549',
              textAlign: 'left',
              top: 483,
              left: 165.5,
              lineHeight: 20,
              MaxLineNumber: 2,
              breakWord: true,
              width: 125
            }
          ]
        }
    

API

对象结构一览
{
  width: 375,
  height: 555,
  views: [
    {
      type: 'image',
      url: 'url',
      top: 0,
      left: 0,
      width: 375,
      height: 555,
      borderRadius: true
    },
    {
      type: 'text',
      content: 'content',
      fontSize: 16,
      color: '#402D16',
      textAlign: 'left',
      top: 33,
      left: 96,
      bolder: true
    },
    {
      type: 'rect',
      background: 'color',
      top: 0,
      left: 0,
      width: 375,
      height: 555,
      shadowBlur: 10,
      shadowColor: "rgba(255,255,255,1)"
    },
    {
      type: 'roundrect',
      background: "#fff",
      y: 57.5,
      x: 88,
      width: 280,
      height: 25,
      radius:10,
      shadowBlur: 10,
      shadowColor: "rgba(255,255,255,1)"
    }
  ]
}

数据对象的第一层需要三个参数: widthheightmodeviews。配置中所有的数字都是没有单位的。这就意味着 canvas 绘制的是一个比例图。具体显示的大小直接把返回的图片路径放置到 image 标签中即可。

mode 可选值有 same, 默认值为空,常规下尽量不要使用。如要使用请看 Q&A的第1点。

当前可以绘制3种类型的配置: imagetextrectroundrect。配置的属性基本上使用的都是 css 的驼峰名称,还是比较好理解的。

image(图片)

属性 含义 默认值 可选值
url 绘制的图片地址,可以是本地图片,如:/images/1.jpeg
top 左上角距离画板顶部的距离
left 左上角距离画板左侧的距离
width 要画多宽 0
height 要画多高 0
borderRadius 是否圆形 0 true
opacity 图片透明度 100 1-100(对应百分比)

text(文本)

属性 含义 默认值 可选值
content 绘制文本 ''(空字符串)
color 颜色 black
fontSize 字体大小 16
textAlign 文字对齐方式 left center、right
lineHeight 行高,只有在多行文本中才有用 20
top 文本左上角距离画板顶部的距离 0
left 文本左上角距离画板左侧的距离 0
breakWord 是否需要换行 false true
MaxLineNumber 最大行数,只有设置 breakWord: true ,当前属性才有效,超出行数内容的显示为... 2
width MaxLineNumber 属性配套使用,width 就是达到换行的宽度
bolder 是否加粗 false true
textDecoration 显示中划线、下划线效果 none underline(下划线)、line-through(中划线)

rect (矩形,线条)

属性 含义 默认值 可选值
background 背景颜色 black
top 左上角距离画板顶部的距离
left 左上角距离画板左侧的距离
width 要画多宽 0
height 要画多高 0
shadowBlur 阴影模糊 0
shadowColor 阴影颜色

roundrect(圆角矩形)

属性 含义 默认值 可选值
background 背景颜色 black
top 左上角距离画板顶部的距离
left 左上角距离画板左侧的距离
width 要画多宽 0
height 要画多高 0
radius 圆角度数 0
shadowBlur 阴影模糊 0
shadowColor 阴影颜色

Q&A

  1. 最佳实践

    绘制操作的时候最好 锁住屏幕 ,例如在点击绘制的时候

    wx.showLoading({
      title: '绘制分享图片中',
      mask: true
    })
    

    绘制完成之后

    wx.hideLoading()
    

他们都在用 esay-canvas

TIPS

如果有什么疑问,欢迎 issues。 如果觉得不错,能不能送我小 ✨ ✨ ,让我有更多的动力。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].