Добавил еще ведущие нули к миллисекундам, если кому-то еще когда-то этот код понадобится
log = function (text, color, define){ var id, time, thread, logHtml, textLog; define = (typeof define == 'string') ? define.split(/[\s,.|:;]+/g) : define; if(typeof define === 'object' && define !== null){ if(Array.isArray(define)){ id = define.indexOf('id') > -1; time = define.indexOf('time') > -1; thread = define.indexOf('thread') > -1; } else{ id = define.id == true; time = define.time == true; thread = define.thread == true; } } else id = time = thread = true; id = id ? '<a href="action://action' + ScriptWorker.GetCurrentAction() + '" style="color:gray;">[' + ScriptWorker.GetCurrentAction() + ']</a>' : ''; time = time ? ' ' + getTime() : ''; thread = thread ? ' Поток №' + thread_number() : ''; logHtml = (id || time || thread) ? id + '<span style="color: white">' + time + thread + ' : </span>' : ''; logHtml += '<span style="color:' + (color ? color : 'white') + '">' + text + '</span>'; textLog = '[' + ScriptWorker.GetCurrentAction() + ']' + time + thread + ' : ' + text function getTime(){ var checkTime = function(i){ return (i < 10) ? "0" + i : i; }; var checkMilliSeconds = function(ms){ if (ms < 10) { return "00" + ms; } else if (ms < 100) { return "0" + ms; } else { return ms; } }; var d = new Date(); var hh = checkTime(d.getHours()); var mm = checkTime(d.getMinutes()); var ss = checkTime(d.getSeconds()); var ms = checkMilliSeconds(d.getMilliseconds()); return '[' + hh + ':' + mm + ':' + ss + '.' + ms + ']'; }; Logger.WriteHtml(logHtml, textLog); }Преобразование текста в изображение
-
Добрый вечер. Есть ли решение которое позволяет преобразовать текст в изображение без пустых полей (чтобы полностью влезал текст по краям)
Текст динамический так что размер изображения может меняться
Сам шаблон с текстом в стандартном методе преобразования выравнивается по центру.
Или может есть другой способ создания изображения при отправке сообщения в канал ТГ, хочу водяные знаки добавить -
@root https://www.npmjs.com/package/text2png
Вот такой код запускаю в BAS. Но выходит ошибка Error: Cannot find module 'text2png'var fs = require('fs');
var text2png = require('text2png');text2png('Example\nText', {
font: '60px Futura',
textColor: 'teal',
bgColor: 'linen',
lineSpacing: 10,
padding: 20
}); -
@root Эта проблема из-за ошибки в установке
Исправляли так - только как это сделать?
Fixed by manually copying files from GTK to canvas/build/Release/И еще видимо модули от canvas надо установить, но как это сделать для BASa - вот в чем вопрос...
Building the node-canvas module requires:
A global installation of node-gyp.
GTK 2
For optional JPEG support (node-canvas 2.0 and later): libjpeg-turbo -
А что мешает выводить блок html и делать скриншот?
К примеру здесь https://jsfiddle.net/pds1qs9c/ -
-
@root теперь попробовал этот модуль для watermark
Таймаут во время выполнения функции на встроенном языке
var watermark = require('image-watermark');
watermark.embedWatermark('12.jpg', {'text' : 'sample watermark'});Файл в папке ...\Roaming\BrowserAutomationStudio\apps\20.7.6 (и прямой путь пробовал)
-
@root там была уже такая проблема в топике на ГХ. Так вроде и не решили
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\anybo\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\anybo\package.json'
npm WARN anybo No description
npm WARN anybo No repository field.
npm WARN anybo No README data
npm WARN anybo No license field.- image-watermark@0.0.7
added 2 packages and updated 1 package in 2.512s
Это я даже в чистом nodejs проверил.
- image-watermark@0.0.7