MCPcopy Index your code
hub / github.com/BuilderIO/SSDiff / resizeImage

Method resizeImage

packages/ssdiff/src/index.ts:137–154  ·  view source on GitHub ↗

* @remarks * This method is internally used to resize the image to the same size, incase the images are of different sizes. * @param image - PNG image * @param width - width to be resized to * @param height - height to be resized to * @returns Resized PNG image with the given width an

(image: PNG, width: number, height: number)

Source from the content-addressed store, hash-verified

135 * @returns Resized PNG image with the given width and height parameters
136 */
137 async resizeImage(image: PNG, width: number, height: number) {
138 try {
139 const sharpImage = sharp(image.data, { raw: { width: image.width, height: image.height, channels: 4 } });
140 // make the resizing configurable if required in future
141 const resizedImageBuffer = await sharpImage
142 .resize({
143 height,
144 width,
145 fit: "contain",
146 position: "left top",
147 })
148 .toFormat("png")
149 .toBuffer();
150 return PNG.sync.read(resizedImageBuffer);
151 } catch (e: any) {
152 throw new Error("Error while resizing image: " + e.message);
153 }
154 }
155
156 async screenshot(url: any) {
157 try {

Callers 2

compareMethod · 0.95
ssdiff.test.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected