Skip to content

Configuration Options

HQ-Cropper accepts a configuration object as the second parameter.

typescript
const cropper = HqCropper(onSubmit, {
    outputSize: 512,
    compression: 0.8,
    type: 'jpeg',
})

All Options

OptionTypeDefaultDescription
portalSizenumber150Initial size of crop portal in pixels
minPortalSizenumber50Minimum portal size (prevents too small crops)
portalPosition[number, number] | 'center''center'Initial portal position
framePaddingnumber3Padding around the image frame
outputSizenumber0Output size in pixels (0 = original selection)
compressionnumber1JPEG compression (0-1, where 1 is best)
type'jpeg' | 'png''jpeg'Output image format
maxFileSizenumber0Max input file size in bytes (0 = no limit)
allowedTypesstring[]['image/jpeg', ...]Allowed MIME types
applyButtonLabelstring'Apply'Apply button text
cancelButtonLabelstring'Cancel'Cancel button text

Output Size

The outputSize option controls the dimensions of the cropped image:

typescript
// Always output 512x512 pixels
const cropper = HqCropper(onSubmit, {
    outputSize: 512,
})

// Use original selection size (default)
const cropper = HqCropper(onSubmit, {
    outputSize: 0,
})

TIP

Use a fixed outputSize for consistent avatar sizes across your application.

Image Format & Compression

typescript
// High quality PNG (lossless)
const cropper = HqCropper(onSubmit, {
    type: 'png',
    compression: 1,
})

// Compressed JPEG for smaller files
const cropper = HqCropper(onSubmit, {
    type: 'jpeg',
    compression: 0.7, // 70% quality
})

File Validation

Restrict allowed file types and sizes:

typescript
const cropper = HqCropper(
    onSubmit,
    {
        maxFileSize: 5 * 1024 * 1024, // 5MB
        allowedTypes: ['image/jpeg', 'image/png'],
    },
    undefined,
    (error) => {
        alert(error) // Show validation error
    }
)

Custom Labels

Localize button labels:

typescript
// Russian
const cropper = HqCropper(onSubmit, {
    applyButtonLabel: 'Применить',
    cancelButtonLabel: 'Отмена',
})

// German
const cropper = HqCropper(onSubmit, {
    applyButtonLabel: 'Anwenden',
    cancelButtonLabel: 'Abbrechen',
})

Portal Configuration

Control the crop selection area:

typescript
const cropper = HqCropper(onSubmit, {
    portalSize: 200, // Initial size
    minPortalSize: 100, // Minimum size
    framePadding: 10, // Padding around image
})

Released under the MIT License.