Modules@robinpath/image
image

@robinpath/image

0.1.1Node.jsPublic

Image processing: resize, crop, convert, watermark, and metadata

Image

Image processing with Sharp: resize, crop, convert, rotate, flip, grayscale, blur, composite/watermark, and thumbnails

Package: @robinpath/image | Category: Other | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the image module when you need to:

  • Resize an image -- Use image.resize to perform this operation
  • Crop a region from an image -- Use image.crop to perform this operation
  • Convert image format (png, jpeg, webp, avif) -- Use image.convert to perform this operation
  • Get image metadata -- Use image.metadata to perform this operation
  • Rotate an image -- Use image.rotate to perform this operation

Quick Reference

FunctionDescriptionReturns
resizeResize an image{path, width, height}
cropCrop a region from an image{path}
convertConvert image format (png, jpeg, webp, avif){path, format}
metadataGet image metadata{width, height, format, channels, size, hasAlpha}
rotateRotate an image{path, angle}
flipFlip an image vertically or horizontally{path}
grayscaleConvert to grayscale{path}
blurApply Gaussian blur{path}
compositeOverlay one image on top of another (watermark){path}
thumbnailGenerate a square thumbnail{path, size}

Functions

resize

Resize an image

Module: image | Returns: object -- {path, width, height}

image.resize "./photo.jpg" "./thumb.jpg" {"width": 300, "height": 200}
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path
optionsobjectYes{width, height, fit}

crop

Crop a region from an image

Module: image | Returns: object -- {path}

image.crop "./photo.jpg" "./cropped.jpg" {"left": 10, "top": 10, "width": 200, "height": 200}
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path
optionsobjectYes{left, top, width, height}

convert

Convert image format (png, jpeg, webp, avif)

Module: image | Returns: object -- {path, format}

image.convert "./photo.png" "./photo.webp" "webp" 85
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path
formatstringYesTarget format
qualitynumberNoQuality 1-100 (optional)

metadata

Get image metadata

Module: image | Returns: object -- {width, height, format, channels, size, hasAlpha}

image.metadata "./photo.jpg"
ParameterTypeRequiredDescription
inputstringYesInput path

rotate

Rotate an image

Module: image | Returns: object -- {path, angle}

image.rotate "./photo.jpg" "./rotated.jpg" 90
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path
anglenumberYesRotation angle in degrees

flip

Flip an image vertically or horizontally

Module: image | Returns: object -- {path}

image.flip "./photo.jpg" "./flipped.jpg" "horizontal"
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path
directionstringNo'vertical' or 'horizontal'

grayscale

Convert to grayscale

Module: image | Returns: object -- {path}

image.grayscale "./photo.jpg" "./bw.jpg"
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path

blur

Apply Gaussian blur

Module: image | Returns: object -- {path}

image.blur "./photo.jpg" "./blurred.jpg" 5
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path
sigmanumberNoBlur sigma (default 3)

composite

Overlay one image on top of another (watermark)

Module: image | Returns: object -- {path}

image.composite "./photo.jpg" "./watermark.png" "./result.jpg" {"gravity": "southeast"}
ParameterTypeRequiredDescription
basestringYesBase image path
overlaystringYesOverlay image path
outputstringYesOutput path
optionsobjectNo{top, left, gravity}

thumbnail

Generate a square thumbnail

Module: image | Returns: object -- {path, size}

image.thumbnail "./photo.jpg" "./thumb.jpg" 150
ParameterTypeRequiredDescription
inputstringYesInput path
outputstringYesOutput path
sizenumberNoSize in pixels (default 200)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Resize and validate result"
do
  set $result as image.resize "./photo.jpg" "./thumb.jpg" {"width": 300, "height": 200}
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Image workflow

Chain multiple image operations together.

@desc "Resize, crop, and more"
do
  set $r_resize as image.resize "./photo.jpg" "./thumb.jpg" {"width": 300, "height": 200}
  set $r_crop as image.crop "./photo.jpg" "./cropped.jpg" {"left": 10, "top": 10, "width": 200, "height": 200}
  set $r_convert as image.convert "./photo.png" "./photo.webp" "webp" 85
  print "All operations complete"
enddo

2. Safe resize with validation

Check results before proceeding.

@desc "Resize and validate result"
do
  set $result as image.resize "./photo.jpg" "./thumb.jpg" {"width": 300, "height": 200}
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/image

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size4.5 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

utilities