MCPcopy
hub / github.com/diegomura/react-pdf / getImageFormat

Function getImageFormat

packages/image/src/resolve.js:121–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119};
120
121const getImageFormat = body => {
122 const isPng =
123 body[0] === 137 &&
124 body[1] === 80 &&
125 body[2] === 78 &&
126 body[3] === 71 &&
127 body[4] === 13 &&
128 body[5] === 10 &&
129 body[6] === 26 &&
130 body[7] === 10;
131
132 const isJpg = body[0] === 255 && body[1] === 216 && body[2] === 255;
133
134 let extension = '';
135 if (isPng) {
136 extension = 'png';
137 } else if (isJpg) {
138 extension = 'jpg';
139 } else {
140 throw new Error('Not valid image extension');
141 }
142
143 return extension;
144};
145
146const resolveImageFromUrl = async src => {
147 const { uri, body, headers, method = 'GET' } = src;

Callers 1

resolveImageFromUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected