下面的python代码如何转换成nodejs,需要用到使用sharp模块
3条回答 默认 最新
- CSDN专家-showbo 2023-10-30 10:13关注
const sharp = require('sharp');//https://sharp.pixelplumbing.com/api-constructor#clone async function parse_bg_captcha(img, im_show = false, save_path = null) { let _img = sharp(img); let { width,height} = await _img.metadata(); ` let bg = _img.extract({ left: 100, top: 100, width: 100, height: 100 }); bg.toFile(save_path); return; console.log(save_path) _img.toFile(save_path); return;` let _Ge=[39, 38, 48, 49, 41, 40, 46, 47, 35, 34, 50, 51, 33, 32, 28, 29, 27, 26, 36, 37, 31, 30, 44, 45, 43, 42, 12, 13, 23, 22, 14, 15, 21, 20, 8, 9, 25, 24, 6, 7, 3, 2, 0, 1, 11, 10, 4, 5, 19, 18, 16, 17]; let [w_sep, h_sep] = [10, 80]; let new_img = sharp({ create: { width: 260, height: 160, channels: 3, background: { r: 255, g: 255, b: 255 } } }); let paste = []; for (let idx = 0; idx < _Ge.length; idx++) { let x = _Ge[idx] % 26 * 12 + 1; let y = _Ge[idx] > 25 ? h_sep : 0; let data = { left: x, top: y, width: w_sep, height: h_sep }; let img_cut; try { img_cut = await _img.clone().extract(data).toBuffer(); } catch (e) { console.log(e, '==>', data); continue } let new_x = idx % 26 * 10 let new_y = idx > 25 ? h_sep : 0; paste.push({ input: img_cut, left: new_x, top: new_y }); } await new_img.composite(paste).toFile(save_path) } parse_bg_captcha('bg.webp',false ,'bg.jpg')
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
- ¥20 关于URL获取的参数,无法执行二选一查询
- ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
- ¥15 marlin编译错误,如何解决?
- ¥15 有偿四位数,节约算法和扫描算法
- ¥15 VUE项目怎么运行,系统打不开
- ¥50 pointpillars等目标检测算法怎么融合注意力机制
- ¥20 Vs code Mac系统 PHP Debug调试环境配置
- ¥60 大一项目课,微信小程序
- ¥15 求视频摘要youtube和ovp数据集