|
|
@ -1,5 +1,4 @@ |
|
|
|
const bmp = require('bmp-js'); |
|
|
|
const bmp = require('bmp-js'); |
|
|
|
const fileType = require('file-type'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* setImage |
|
|
|
* setImage |
|
|
@ -9,7 +8,8 @@ const fileType = require('file-type'); |
|
|
|
* @access public |
|
|
|
* @access public |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
module.exports = (TessModule, api, image, angle = 0) => { |
|
|
|
module.exports = (TessModule, api, image, angle = 0) => { |
|
|
|
const type = fileType(image); |
|
|
|
// Check for bmp magic numbers (42 and 4D in hex)
|
|
|
|
|
|
|
|
const isBmp = (image[0] === 66 && image[1] === 77) || (image[1] === 66 && image[0] === 77); |
|
|
|
|
|
|
|
|
|
|
|
const exif = image.slice(0, 500).toString().match(/\x01\x12\x00\x03\x00\x00\x00\x01\x00(.)/)?.[1]?.charCodeAt(0) || 1; |
|
|
|
const exif = image.slice(0, 500).toString().match(/\x01\x12\x00\x03\x00\x00\x00\x01\x00(.)/)?.[1]?.charCodeAt(0) || 1; |
|
|
|
|
|
|
|
|
|
|
@ -18,7 +18,7 @@ module.exports = (TessModule, api, image, angle = 0) => { |
|
|
|
// * @see https://github.com/DanBloomberg/leptonica/issues/607#issuecomment-1068802516
|
|
|
|
// * @see https://github.com/DanBloomberg/leptonica/issues/607#issuecomment-1068802516
|
|
|
|
// * We therefore use bmp-js to convert all bmp files into a format Leptonica is known to support
|
|
|
|
// * We therefore use bmp-js to convert all bmp files into a format Leptonica is known to support
|
|
|
|
// */
|
|
|
|
// */
|
|
|
|
if (type && type.mime === 'image/bmp') { |
|
|
|
if (isBmp) { |
|
|
|
// Not sure what this line actually does, but removing breaks the function
|
|
|
|
// Not sure what this line actually does, but removing breaks the function
|
|
|
|
const buf = Buffer.from(Array.from({ ...image, length: Object.keys(image).length })); |
|
|
|
const buf = Buffer.from(Array.from({ ...image, length: Object.keys(image).length })); |
|
|
|
const bmpBuf = bmp.decode(buf); |
|
|
|
const bmpBuf = bmp.decode(buf); |
|
|
|