* @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)
| 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 { |
no outgoing calls
no test coverage detected