image.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /**
  2. * @node image
  3. * @name Image
  4. * @category media
  5. * @version 1.0.0
  6. * @description Extract image information, metadata, and EXIF data using ImageMagick
  7. * @icon image
  8. */
  9. const configSchema = {
  10. type: 'object',
  11. properties: {
  12. operation: {
  13. type: 'string',
  14. title: 'Operation',
  15. enum: ['info', 'resize', 'crop', 'rotate', 'filter', 'convert'],
  16. enumLabels: ['Info', 'Resize', 'Crop', 'Rotate', 'Filter', 'Convert Format'],
  17. default: 'info',
  18. description: 'Image operation to perform'
  19. },
  20. inputSource: {
  21. type: 'string',
  22. title: 'Input Source',
  23. enum: ['auto', 'base64', 'filePath', 'url', 'storage'],
  24. enumLabels: ['Auto-detect', 'Base64 Data', 'File Path', 'URL', 'Storage Reference'],
  25. default: 'auto',
  26. description: 'Source type for the input image'
  27. },
  28. base64Data: {
  29. type: 'string',
  30. title: 'Base64 Image Data',
  31. description: 'Base64-encoded image data. Supports {{variable}} interpolation.',
  32. showWhen: { field: 'inputSource', value: 'base64' }
  33. },
  34. filePath: {
  35. type: 'string',
  36. title: 'File Path',
  37. description: 'Path to image file on runner filesystem. Supports {{variable}} interpolation.',
  38. showWhen: { field: 'inputSource', value: 'filePath' }
  39. },
  40. url: {
  41. type: 'string',
  42. title: 'Image URL',
  43. description: 'URL to download image from. Supports {{variable}} interpolation.',
  44. showWhen: { field: 'inputSource', value: 'url' }
  45. },
  46. storageCollection: {
  47. type: 'string',
  48. title: 'Storage Collection',
  49. description: 'Collection name for stored image',
  50. showWhen: { field: 'inputSource', value: 'storage' }
  51. },
  52. storageId: {
  53. type: 'string',
  54. title: 'Storage Document ID',
  55. description: 'Document ID in storage collection. Supports {{variable}} interpolation.',
  56. showWhen: { field: 'inputSource', value: 'storage' }
  57. },
  58. includeExif: {
  59. type: 'boolean',
  60. title: 'Include EXIF Metadata',
  61. default: true,
  62. description: 'Extract EXIF metadata (camera info, GPS, date taken, etc.)',
  63. showWhen: { field: 'operation', value: 'info' }
  64. },
  65. timeout: {
  66. type: 'number',
  67. title: 'Timeout (ms)',
  68. default: 30000,
  69. minimum: 1000,
  70. maximum: 120000,
  71. description: 'Maximum time to wait for image processing'
  72. }
  73. },
  74. required: ['operation']
  75. };
  76. const inputSchema = {
  77. type: 'object',
  78. properties: {
  79. data: {
  80. type: 'any',
  81. description: 'Input data. Can be base64 string, file path, URL, or binary object from another node.'
  82. },
  83. file: {
  84. type: 'object',
  85. description: 'Binary file object with type, data (base64), mimeType, filename'
  86. },
  87. storage: {
  88. type: 'object',
  89. description: 'Storage reference with collection and id'
  90. },
  91. base64: {
  92. type: 'string',
  93. description: 'Base64-encoded image data'
  94. },
  95. filePath: {
  96. type: 'string',
  97. description: 'Override file path from input'
  98. },
  99. url: {
  100. type: 'string',
  101. description: 'Override URL from input'
  102. }
  103. }
  104. };
  105. const outputSchema = {
  106. type: 'object',
  107. properties: {
  108. width: {
  109. type: 'number',
  110. description: 'Image width in pixels'
  111. },
  112. height: {
  113. type: 'number',
  114. description: 'Image height in pixels'
  115. },
  116. format: {
  117. type: 'string',
  118. description: 'Image format (JPEG, PNG, GIF, etc.)'
  119. },
  120. colorSpace: {
  121. type: 'string',
  122. description: 'Color space (sRGB, CMYK, Grayscale, etc.)'
  123. },
  124. depth: {
  125. type: 'number',
  126. description: 'Bit depth per channel'
  127. },
  128. fileSize: {
  129. type: 'number',
  130. description: 'File size in bytes'
  131. },
  132. dpi: {
  133. type: 'object',
  134. description: 'DPI/resolution information',
  135. properties: {
  136. x: { type: 'number' },
  137. y: { type: 'number' },
  138. unit: { type: 'string' }
  139. }
  140. },
  141. hasAlpha: {
  142. type: 'boolean',
  143. description: 'Whether image has alpha/transparency channel'
  144. },
  145. compression: {
  146. type: 'string',
  147. description: 'Compression type used'
  148. },
  149. exif: {
  150. type: 'object',
  151. description: 'EXIF metadata (if available)',
  152. properties: {
  153. camera: {
  154. type: 'object',
  155. properties: {
  156. make: { type: 'string' },
  157. model: { type: 'string' },
  158. software: { type: 'string' }
  159. }
  160. },
  161. datetime: {
  162. type: 'object',
  163. properties: {
  164. original: { type: 'string' },
  165. digitized: { type: 'string' },
  166. modified: { type: 'string' }
  167. }
  168. },
  169. gps: {
  170. type: 'object',
  171. properties: {
  172. latitude: { type: 'number' },
  173. longitude: { type: 'number' },
  174. altitude: { type: 'number' },
  175. latitudeRef: { type: 'string' },
  176. longitudeRef: { type: 'string' }
  177. }
  178. },
  179. exposure: {
  180. type: 'object',
  181. properties: {
  182. time: { type: 'string' },
  183. fNumber: { type: 'number' },
  184. iso: { type: 'number' },
  185. program: { type: 'string' },
  186. bias: { type: 'string' }
  187. }
  188. },
  189. lens: {
  190. type: 'object',
  191. properties: {
  192. focalLength: { type: 'string' },
  193. focalLength35mm: { type: 'number' },
  194. aperture: { type: 'number' },
  195. make: { type: 'string' },
  196. model: { type: 'string' }
  197. }
  198. },
  199. orientation: { type: 'number' },
  200. flash: { type: 'string' },
  201. whiteBalance: { type: 'string' },
  202. meteringMode: { type: 'string' }
  203. }
  204. },
  205. sourceType: {
  206. type: 'string',
  207. description: 'Source type used (base64, filePath, url, storage)'
  208. },
  209. sourcePath: {
  210. type: 'string',
  211. description: 'Temporary file path used for processing'
  212. }
  213. }
  214. };
  215. function interpolate(template, data) {
  216. if (typeof template !== 'string') return template;
  217. return template.replace(/\{\{([^}]+)\}\}/g, function(match, key) {
  218. var keys = key.trim().split('.');
  219. var value = data;
  220. for (var i = 0; i < keys.length; i++) {
  221. if (value && typeof value === 'object' && keys[i] in value) {
  222. value = value[keys[i]];
  223. } else {
  224. return match;
  225. }
  226. }
  227. return value !== undefined ? String(value) : match;
  228. });
  229. }
  230. function generateTempPath(extension) {
  231. var uuid = smartbotic.utils.uuid();
  232. return '/tmp/smartbotic-image-' + uuid + (extension ? '.' + extension : '');
  233. }
  234. function detectImageFormat(base64Data) {
  235. if (!base64Data || base64Data.length < 8) return null;
  236. var header = smartbotic.utils.base64Decode(base64Data.substring(0, 16));
  237. if (!header) return null;
  238. if (header.charCodeAt(0) === 0xFF && header.charCodeAt(1) === 0xD8 && header.charCodeAt(2) === 0xFF) {
  239. return 'jpg';
  240. }
  241. if (header.substring(0, 8) === '\x89PNG\r\n\x1a\n') {
  242. return 'png';
  243. }
  244. if (header.substring(0, 6) === 'GIF87a' || header.substring(0, 6) === 'GIF89a') {
  245. return 'gif';
  246. }
  247. if (header.substring(0, 4) === 'RIFF' && header.substring(8, 12) === 'WEBP') {
  248. return 'webp';
  249. }
  250. if (header.substring(0, 2) === 'BM') {
  251. return 'bmp';
  252. }
  253. if (header.substring(0, 4) === 'II*\x00' || header.substring(0, 4) === 'MM\x00*') {
  254. return 'tiff';
  255. }
  256. return null;
  257. }
  258. function resolveImageInput(config, input) {
  259. var inputSource = config.inputSource || 'auto';
  260. var result = { type: null, data: null, path: null, tempPath: null };
  261. if (inputSource === 'filePath' || (inputSource === 'auto' && input.filePath)) {
  262. var filePath = input.filePath || interpolate(config.filePath, input);
  263. if (filePath && smartbotic.fs.exists(filePath)) {
  264. result.type = 'filePath';
  265. result.path = filePath;
  266. return result;
  267. }
  268. }
  269. if (inputSource === 'base64' || (inputSource === 'auto' && (input.base64 || config.base64Data))) {
  270. var base64 = input.base64 || interpolate(config.base64Data, input);
  271. if (base64) {
  272. result.type = 'base64';
  273. result.data = base64;
  274. return result;
  275. }
  276. }
  277. if (inputSource === 'url' || (inputSource === 'auto' && (input.url || config.url))) {
  278. var url = input.url || interpolate(config.url, input);
  279. if (url) {
  280. result.type = 'url';
  281. result.data = url;
  282. return result;
  283. }
  284. }
  285. if (inputSource === 'storage' || (inputSource === 'auto' && input.storage)) {
  286. var collection = input.storage ? input.storage.collection : config.storageCollection;
  287. var id = input.storage ? input.storage.id : interpolate(config.storageId, input);
  288. if (collection && id) {
  289. result.type = 'storage';
  290. result.data = { collection: collection, id: id };
  291. return result;
  292. }
  293. }
  294. if (inputSource === 'auto') {
  295. if (input.file && input.file.type === 'binary' && input.file.data) {
  296. result.type = 'base64';
  297. result.data = input.file.data;
  298. return result;
  299. }
  300. if (typeof input.data === 'string') {
  301. if (input.data.match(/^[A-Za-z0-9+/]+=*$/) && input.data.length > 100) {
  302. result.type = 'base64';
  303. result.data = input.data;
  304. return result;
  305. }
  306. if (input.data.startsWith('http://') || input.data.startsWith('https://')) {
  307. result.type = 'url';
  308. result.data = input.data;
  309. return result;
  310. }
  311. if (smartbotic.fs.exists(input.data)) {
  312. result.type = 'filePath';
  313. result.path = input.data;
  314. return result;
  315. }
  316. }
  317. if (input.data && typeof input.data === 'object') {
  318. if (input.data.type === 'binary' && input.data.data) {
  319. result.type = 'base64';
  320. result.data = input.data.data;
  321. return result;
  322. }
  323. if (input.data.collection && input.data.id) {
  324. result.type = 'storage';
  325. result.data = input.data;
  326. return result;
  327. }
  328. }
  329. }
  330. return result;
  331. }
  332. function prepareImageFile(imageInput, timeout) {
  333. var tempPath = null;
  334. if (imageInput.type === 'filePath') {
  335. return { path: imageInput.path, tempPath: null };
  336. }
  337. if (imageInput.type === 'base64') {
  338. var ext = detectImageFormat(imageInput.data) || 'img';
  339. tempPath = generateTempPath(ext);
  340. var writeResult = smartbotic.fs.writeFile(tempPath, imageInput.data, 'base64');
  341. if (!writeResult.success) {
  342. throw new Error('Failed to write temp file: ' + (writeResult.error || 'Unknown error'));
  343. }
  344. return { path: tempPath, tempPath: tempPath };
  345. }
  346. if (imageInput.type === 'url') {
  347. smartbotic.log.info('Downloading image from URL: ' + imageInput.data);
  348. var response = smartbotic.http.request({
  349. method: 'GET',
  350. url: imageInput.data,
  351. timeout: timeout
  352. });
  353. if (response.status < 200 || response.status >= 300) {
  354. throw new Error('Failed to download image: HTTP ' + response.status);
  355. }
  356. var contentType = response.headers['content-type'] || '';
  357. var ext = 'img';
  358. if (contentType.includes('jpeg') || contentType.includes('jpg')) ext = 'jpg';
  359. else if (contentType.includes('png')) ext = 'png';
  360. else if (contentType.includes('gif')) ext = 'gif';
  361. else if (contentType.includes('webp')) ext = 'webp';
  362. tempPath = generateTempPath(ext);
  363. var base64Data = smartbotic.utils.base64Encode(response.data);
  364. var writeResult = smartbotic.fs.writeFile(tempPath, base64Data, 'base64');
  365. if (!writeResult.success) {
  366. throw new Error('Failed to write downloaded image: ' + (writeResult.error || 'Unknown error'));
  367. }
  368. return { path: tempPath, tempPath: tempPath };
  369. }
  370. if (imageInput.type === 'storage') {
  371. var storageResult = smartbotic.storage.get(imageInput.data.collection, imageInput.data.id);
  372. if (!storageResult.found) {
  373. throw new Error('Image not found in storage: ' + imageInput.data.collection + '/' + imageInput.data.id);
  374. }
  375. var doc = storageResult.document;
  376. var base64Data = doc.data || doc.content || doc.base64;
  377. if (!base64Data) {
  378. throw new Error('Storage document does not contain image data');
  379. }
  380. var ext = detectImageFormat(base64Data) || 'img';
  381. tempPath = generateTempPath(ext);
  382. var writeResult = smartbotic.fs.writeFile(tempPath, base64Data, 'base64');
  383. if (!writeResult.success) {
  384. throw new Error('Failed to write storage image: ' + (writeResult.error || 'Unknown error'));
  385. }
  386. return { path: tempPath, tempPath: tempPath };
  387. }
  388. throw new Error('No valid image input found');
  389. }
  390. function cleanupTempFile(tempPath) {
  391. if (tempPath) {
  392. try {
  393. smartbotic.fs.unlink(tempPath);
  394. } catch (e) {
  395. smartbotic.log.warn('Failed to cleanup temp file: ' + tempPath);
  396. }
  397. }
  398. }
  399. function parseImageMagickInfo(output) {
  400. var info = {};
  401. var lines = output.split('\n');
  402. for (var i = 0; i < lines.length; i++) {
  403. var line = lines[i].trim();
  404. if (!line) continue;
  405. var colonIdx = line.indexOf(':');
  406. if (colonIdx > 0) {
  407. var key = line.substring(0, colonIdx).trim().toLowerCase();
  408. var value = line.substring(colonIdx + 1).trim();
  409. if (key === 'image' || key === 'format') {
  410. var formatMatch = value.match(/^(\w+)/);
  411. if (formatMatch) info.format = formatMatch[1].toUpperCase();
  412. }
  413. else if (key === 'geometry' || key === 'page geometry') {
  414. var geomMatch = value.match(/(\d+)x(\d+)/);
  415. if (geomMatch) {
  416. info.width = parseInt(geomMatch[1], 10);
  417. info.height = parseInt(geomMatch[2], 10);
  418. }
  419. }
  420. else if (key === 'colorspace') {
  421. info.colorSpace = value;
  422. }
  423. else if (key === 'depth') {
  424. var depthMatch = value.match(/(\d+)/);
  425. if (depthMatch) info.depth = parseInt(depthMatch[1], 10);
  426. }
  427. else if (key === 'channel depth' || key === 'channels') {
  428. if (value.toLowerCase().includes('alpha')) {
  429. info.hasAlpha = true;
  430. }
  431. }
  432. else if (key === 'alpha') {
  433. info.hasAlpha = value.toLowerCase() !== 'undefined' && value.toLowerCase() !== 'off';
  434. }
  435. else if (key === 'compression') {
  436. info.compression = value;
  437. }
  438. else if (key === 'resolution' || key === 'units') {
  439. if (!info.dpi) info.dpi = {};
  440. var resMatch = value.match(/([\d.]+)x([\d.]+)/);
  441. if (resMatch) {
  442. info.dpi.x = parseFloat(resMatch[1]);
  443. info.dpi.y = parseFloat(resMatch[2]);
  444. }
  445. if (value.includes('PixelsPerInch')) info.dpi.unit = 'dpi';
  446. else if (value.includes('PixelsPerCentimeter')) info.dpi.unit = 'dpcm';
  447. }
  448. else if (key === 'filesize') {
  449. var sizeMatch = value.match(/([\d.]+)\s*(\w+)/);
  450. if (sizeMatch) {
  451. var size = parseFloat(sizeMatch[1]);
  452. var unit = sizeMatch[2].toUpperCase();
  453. if (unit === 'B') info.fileSize = Math.round(size);
  454. else if (unit === 'KB' || unit === 'KIB') info.fileSize = Math.round(size * 1024);
  455. else if (unit === 'MB' || unit === 'MIB') info.fileSize = Math.round(size * 1024 * 1024);
  456. else if (unit === 'GB' || unit === 'GIB') info.fileSize = Math.round(size * 1024 * 1024 * 1024);
  457. }
  458. }
  459. }
  460. }
  461. if (info.hasAlpha === undefined) info.hasAlpha = false;
  462. return info;
  463. }
  464. function parseExifToolOutput(output) {
  465. var exif = {
  466. camera: {},
  467. datetime: {},
  468. gps: {},
  469. exposure: {},
  470. lens: {}
  471. };
  472. var lines = output.split('\n');
  473. for (var i = 0; i < lines.length; i++) {
  474. var line = lines[i].trim();
  475. if (!line) continue;
  476. var colonIdx = line.indexOf(':');
  477. if (colonIdx <= 0) continue;
  478. var key = line.substring(0, colonIdx).trim().toLowerCase().replace(/\s+/g, '');
  479. var value = line.substring(colonIdx + 1).trim();
  480. if (!value || value === '-' || value === 'n/a') continue;
  481. if (key === 'make' || key === 'cameramake') exif.camera.make = value;
  482. else if (key === 'model' || key === 'cameramodel' || key === 'cameramodelname') exif.camera.model = value;
  483. else if (key === 'software') exif.camera.software = value;
  484. else if (key === 'datetimeoriginal' || key === 'createdate') exif.datetime.original = value;
  485. else if (key === 'datetimedigitized' || key === 'digitizeddate') exif.datetime.digitized = value;
  486. else if (key === 'modifydate' || key === 'datetime') exif.datetime.modified = value;
  487. else if (key === 'gpslatitude') {
  488. var latMatch = value.match(/([\d.]+)/);
  489. if (latMatch) {
  490. exif.gps.latitude = parseFloat(latMatch[1]);
  491. if (value.includes('S')) exif.gps.latitude = -exif.gps.latitude;
  492. exif.gps.latitudeRef = value.includes('S') ? 'S' : 'N';
  493. }
  494. }
  495. else if (key === 'gpslongitude') {
  496. var lonMatch = value.match(/([\d.]+)/);
  497. if (lonMatch) {
  498. exif.gps.longitude = parseFloat(lonMatch[1]);
  499. if (value.includes('W')) exif.gps.longitude = -exif.gps.longitude;
  500. exif.gps.longitudeRef = value.includes('W') ? 'W' : 'E';
  501. }
  502. }
  503. else if (key === 'gpsaltitude') {
  504. var altMatch = value.match(/([\d.]+)/);
  505. if (altMatch) exif.gps.altitude = parseFloat(altMatch[1]);
  506. }
  507. else if (key === 'exposuretime' || key === 'shutterspeed') exif.exposure.time = value;
  508. else if (key === 'fnumber' || key === 'aperture') {
  509. var fMatch = value.match(/([\d.]+)/);
  510. if (fMatch) exif.exposure.fNumber = parseFloat(fMatch[1]);
  511. }
  512. else if (key === 'iso' || key === 'isospeedratings') {
  513. var isoMatch = value.match(/(\d+)/);
  514. if (isoMatch) exif.exposure.iso = parseInt(isoMatch[1], 10);
  515. }
  516. else if (key === 'exposureprogram') exif.exposure.program = value;
  517. else if (key === 'exposurecompensation' || key === 'exposurebias') exif.exposure.bias = value;
  518. else if (key === 'focallength') exif.lens.focalLength = value;
  519. else if (key === 'focallengthin35mmformat' || key === 'focallength35efl') {
  520. var fl35Match = value.match(/(\d+)/);
  521. if (fl35Match) exif.lens.focalLength35mm = parseInt(fl35Match[1], 10);
  522. }
  523. else if (key === 'maxaperturevalue') {
  524. var apMatch = value.match(/([\d.]+)/);
  525. if (apMatch) exif.lens.aperture = parseFloat(apMatch[1]);
  526. }
  527. else if (key === 'lensmake') exif.lens.make = value;
  528. else if (key === 'lensmodel' || key === 'lens') exif.lens.model = value;
  529. else if (key === 'orientation') {
  530. var oriMatch = value.match(/(\d)/);
  531. if (oriMatch) exif.orientation = parseInt(oriMatch[1], 10);
  532. }
  533. else if (key === 'flash') exif.flash = value;
  534. else if (key === 'whitebalance') exif.whiteBalance = value;
  535. else if (key === 'meteringmode') exif.meteringMode = value;
  536. }
  537. var hasData = false;
  538. for (var section in exif) {
  539. if (typeof exif[section] === 'object') {
  540. for (var field in exif[section]) {
  541. if (exif[section][field] !== undefined) {
  542. hasData = true;
  543. break;
  544. }
  545. }
  546. } else if (exif[section] !== undefined) {
  547. hasData = true;
  548. }
  549. if (hasData) break;
  550. }
  551. return hasData ? exif : null;
  552. }
  553. function executeInfoOperation(imagePath, includeExif, timeout) {
  554. smartbotic.log.info('Running ImageMagick identify on: ' + imagePath);
  555. var identifyCmd = 'identify -verbose "' + imagePath.replace(/"/g, '\\"') + '"';
  556. var identifyResult = smartbotic.process.exec(identifyCmd, { timeout: timeout });
  557. if (!identifyResult.success) {
  558. throw new Error('ImageMagick identify failed: ' + (identifyResult.stderr || 'Unknown error'));
  559. }
  560. var info = parseImageMagickInfo(identifyResult.stdout);
  561. var stat = smartbotic.fs.stat(imagePath);
  562. if (stat.success && !info.fileSize) {
  563. info.fileSize = stat.size;
  564. }
  565. if (includeExif) {
  566. smartbotic.log.info('Extracting EXIF metadata');
  567. var exiftoolCmd = 'exiftool "' + imagePath.replace(/"/g, '\\"') + '"';
  568. var exifResult = smartbotic.process.exec(exiftoolCmd, { timeout: timeout });
  569. if (exifResult.success && exifResult.stdout) {
  570. var exifData = parseExifToolOutput(exifResult.stdout);
  571. if (exifData) {
  572. info.exif = exifData;
  573. }
  574. } else {
  575. smartbotic.log.debug('No EXIF data available or exiftool not installed');
  576. }
  577. }
  578. return info;
  579. }
  580. async function execute(config, input, context) {
  581. var operation = config.operation || 'info';
  582. var timeout = config.timeout || 30000;
  583. if (operation !== 'info') {
  584. throw new Error('Operation "' + operation + '" is not yet implemented. Only "info" is available in this version.');
  585. }
  586. var imageInput = resolveImageInput(config, input);
  587. if (!imageInput.type) {
  588. throw new Error('No valid image input found. Provide base64 data, file path, URL, or storage reference.');
  589. }
  590. smartbotic.log.info('Image input source: ' + imageInput.type);
  591. var fileInfo = null;
  592. try {
  593. fileInfo = prepareImageFile(imageInput, timeout);
  594. smartbotic.log.info('Processing image: ' + fileInfo.path);
  595. var result = executeInfoOperation(fileInfo.path, config.includeExif !== false, timeout);
  596. result.sourceType = imageInput.type;
  597. result.sourcePath = fileInfo.path;
  598. return result;
  599. } finally {
  600. if (fileInfo && fileInfo.tempPath) {
  601. cleanupTempFile(fileInfo.tempPath);
  602. }
  603. }
  604. }
  605. module.exports = { configSchema, inputSchema, outputSchema, execute };