@make-u-free/migi 0.5.10 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/tools.js +20 -9
package/package.json
CHANGED
package/src/tools.js
CHANGED
|
@@ -134,14 +134,22 @@ function extractImagesFromPdf(buf) {
|
|
|
134
134
|
const images = []
|
|
135
135
|
let i = 0
|
|
136
136
|
|
|
137
|
-
while (i < buf.length -
|
|
138
|
-
// JPEG: FF D8
|
|
139
|
-
if (buf[i] === 0xFF && buf[i + 1] === 0xD8) {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
while (i < buf.length - 3) {
|
|
138
|
+
// JPEG: FF D8 で始まり、直後に FF E0〜EF(APPマーカー)か FF DB(DQT)が続く本物だけ拾う
|
|
139
|
+
if (buf[i] === 0xFF && buf[i + 1] === 0xD8 && buf[i + 2] === 0xFF) {
|
|
140
|
+
const nextMarker = buf[i + 3]
|
|
141
|
+
const isApp = nextMarker >= 0xE0 && nextMarker <= 0xEF // JFIF / EXIF 等
|
|
142
|
+
const isDqt = nextMarker === 0xDB // 量子化テーブル
|
|
143
|
+
if (isApp || isDqt) {
|
|
144
|
+
const eoiIdx = buf.indexOf(Buffer.from([0xFF, 0xD9]), i + 4)
|
|
145
|
+
if (eoiIdx === -1) break
|
|
146
|
+
const data = buf.slice(i, eoiIdx + 2)
|
|
147
|
+
if (data.length > 1024) { // 1KB未満はアイコン等のゴミなので除外
|
|
148
|
+
images.push({ data, mime: 'image/jpeg' })
|
|
149
|
+
}
|
|
150
|
+
i = eoiIdx + 2
|
|
151
|
+
continue
|
|
152
|
+
}
|
|
145
153
|
}
|
|
146
154
|
|
|
147
155
|
// PNG: 89 50 4E 47 0D 0A 1A 0A で始まる
|
|
@@ -152,7 +160,10 @@ function extractImagesFromPdf(buf) {
|
|
|
152
160
|
) {
|
|
153
161
|
const iend = buf.indexOf(Buffer.from([0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82]), i + 8)
|
|
154
162
|
if (iend === -1) break
|
|
155
|
-
|
|
163
|
+
const data = buf.slice(i, iend + 8)
|
|
164
|
+
if (data.length > 1024) {
|
|
165
|
+
images.push({ data, mime: 'image/png' })
|
|
166
|
+
}
|
|
156
167
|
i = iend + 8
|
|
157
168
|
continue
|
|
158
169
|
}
|