node-html-to-image制作英文单词学习卡片

一、基本说明

上一篇文章介绍了node-html-to-image介绍及功能演示简单介绍了node-html-to-image的功能
本篇根据上述文章的介绍,用node-html-to-image实现制作英文单词学习卡片

二、制作步骤

1、设计思路

卡片尺寸:320×480像素

上部分:英文单词 + 音标

下部分:中文释义+例句

简洁美观的界面,适合学习使用

2、代码实现

单词数据

const vocabularyWords = [
  { word: 'Serendipity', phonetic: /ˌserənˈdɪpəti/, chinese: '意外发现美好事物的能力',example:"Traveling is full of serendipity, the joy of discovering something by chance" },
  { word: 'Ephemeral', phonetic: /ɪˈfemərəl/, chinese: '短暂的,转瞬即逝的' ,example:"Beauty is ephemeral, but memories last forever"},
  { word: 'Resilience', phonetic: /rɪˈzɪl.i.əns/, chinese: '恢复力,适应力' ,example:"Her resilience in the face of adversity was admirable"}
];

卡片上下两部分显示风格

 .card-top {
     min-height: 40%;
     max-height: 60%;
     overflow-y: auto;
     background: linear-gradient(135deg, #a1c4fd, #c2e9fb);
     display: flex;
     flex-direction: column;
     justify-content: center;
     align-items: center;
     padding: 20px;
     text-align: center;
     color: white;
 }
 .card-bottom {
     height: 50%;
     background:linear-gradient(135deg, #c2e9fb, #a1c4fd);
     display: flex;
     flex-direction: column;
     justify-content: center;
     align-items: center;
     padding: 20px;
     text-align: center;
     color: white;
 }

执行主程序

    try {
      await nodeHtmlToImage({
        html: cardHtml,
        output: outputPath,
        transparent: false,
        quality: 100,
        puppeteerArgs: {
          args: ['--no-sandbox', '--disable-setuid-sandbox']
        }

      });
      console.log(`成功生成卡片: ${outputPath}`);
    } catch (error) {
      console.error(`生成卡片时出错: ${error}`);
    }

三、结果展示

生成的单词学习卡片如下图所示
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
源代码下载链接:https://download.youkuaiyun.com/download/yhyvc/90996113

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值