MCPcopy
hub / github.com/Lulzx/tinypdf / image

Function image

src/index.ts:191–220  ·  view source on GitHub ↗
(jpegBytes: Uint8Array, x: number, y: number, w: number, h: number)

Source from the content-addressed store, hash-verified

189 },
190
191 image(jpegBytes: Uint8Array, x: number, y: number, w: number, h: number) {
192 let imgWidth = 0, imgHeight = 0
193 for (let i = 0; i < jpegBytes.length - 1; i++) {
194 if (jpegBytes[i] === 0xFF && (jpegBytes[i + 1] === 0xC0 || jpegBytes[i + 1] === 0xC2)) {
195 imgHeight = (jpegBytes[i + 5] << 8) | jpegBytes[i + 6]
196 imgWidth = (jpegBytes[i + 7] << 8) | jpegBytes[i + 8]
197 break
198 }
199 }
200
201 const imgName = `/Im${imageCount++}`
202
203 const imgRef = addObject({
204 Type: '/XObject',
205 Subtype: '/Image',
206 Width: imgWidth,
207 Height: imgHeight,
208 ColorSpace: '/DeviceRGB',
209 BitsPerComponent: 8,
210 Filter: '/DCTDecode',
211 Length: jpegBytes.length
212 }, jpegBytes)
213
214 images.push({ name: imgName, ref: imgRef })
215
216 ops.push('q')
217 ops.push(`${w.toFixed(2)} 0 0 ${h.toFixed(2)} ${x.toFixed(2)} ${y.toFixed(2)} cm`)
218 ops.push(`${imgName} Do`)
219 ops.push('Q')
220 }
221 }
222
223 fn(ctx)

Callers

nothing calls this directly

Calls 1

addObjectFunction · 0.85

Tested by

no test coverage detected