CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sharp

High performance Node.js image processing library for resizing JPEG, PNG, WebP, GIF, AVIF and TIFF images

80

1.01x
Overview
Eval results
Files

task.mdevals/scenario-9/

Image Border Trimmer

Build a utility that automatically removes uniform borders from images.

Requirements

Create a module that processes images by detecting and removing uniform-colored borders around the edges. The module should analyze the image to identify areas where the border color is similar to the corners and trim those areas away, leaving only the meaningful content.

The utility should handle common image formats and should be able to:

  • Detect uniform borders automatically based on corner pixels
  • Trim borders from all four sides of the image
  • Allow configuration of detection sensitivity
  • Preserve the internal content of the image
  • Maintain the original format and quality

Input and Output

The module should accept an input image file and produce an output image file with borders removed. It should work with common formats like JPEG, PNG, and WebP.

Test Cases

  • Given an image with a 50-pixel white border on all sides, the output image should have the white border removed and dimensions reduced by 100 pixels in both width and height @test
  • Given an image with no uniform border, the output image should be identical to the input image @test
  • Given an image with a colored border (e.g., black), the output should have the colored border removed @test

Implementation

@generates

API

/**
 * Trims uniform borders from an image.
 *
 * @param {string} inputPath - Path to the input image file
 * @param {string} outputPath - Path where the trimmed image will be saved
 * @param {Object} options - Configuration options
 * @param {number} [options.threshold=10] - Similarity threshold for border detection (0-100)
 * @returns {Promise<Object>} Promise resolving to an object with trimming information
 */
async function trimBorders(inputPath, outputPath, options = {}) {
  // Implementation here
}

module.exports = { trimBorders };

Dependencies { .dependencies }

sharp { .dependency }

Provides image processing capabilities including border detection and trimming.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-sharp

tile.json