or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

PDF Thumbnail Generator with Aspect Ratio Control

Build a thumbnail generation system that converts PDF pages to images while maintaining proper aspect ratios.

Requirements

Your system should support two thumbnail generation modes:

Fixed-Width Thumbnails

Generate thumbnails with a fixed width where the height is automatically calculated to preserve the original page proportions.

  • When given a PDF and a target width, produce an image with that exact width @test
  • The height must be automatically determined to maintain the PDF page's aspect ratio @test

Bounded Thumbnails

Generate thumbnails that fit within maximum dimensions while preserving aspect ratio.

  • When given maximum width and height constraints, produce an image that fits within those bounds @test
  • The image must maintain the original aspect ratio and not exceed either dimension @test

Implementation

@generates

API

/**
 * Generates a thumbnail from a PDF with aspect ratio preservation.
 *
 * @param {string} pdfPath - Path to the PDF file
 * @param {Object} options - Thumbnail generation options
 * @param {number} options.width - Target or maximum width in pixels
 * @param {number} [options.height] - Maximum height in pixels (optional for fixed-width mode)
 * @param {string} options.outputPath - Directory to save the thumbnail
 * @param {string} options.filename - Base filename for the thumbnail
 * @returns {Promise<Object>} Thumbnail metadata including dimensions and file path
 */
async function generateThumbnail(pdfPath, options) {
  // IMPLEMENTATION HERE
}

module.exports = { generateThumbnail };

Dependencies { .dependencies }

pdf2pic { .dependency }

Provides PDF to image conversion support.