npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

moleculer-sharp

v1.0.0

Published

A sharp wrapper as a service for the moleculer framework

Downloads

6

Readme

Moleculer logo FOSSA Status

Build Status Coverage Status Codacy Badge Maintainability Known Vulnerabilities npm version Run in Postman

Image Manipulation Service for the Moleculer framework

This Services provides actions for manipulating images using the super fast Sharp module. It utilizes the file streaming capabilities of the moleculer framework

Features

The following List details which features are implemented

  • Obtain Metadata of an image at a path, being streamed or available via http(s)
  • Obtain Channel Statistics of an image at a path, being streamed or available via http(s)
  • Process an image with all manipulation and transformation methods available in Sharp (such as rotation, flip, convert, resize etc)

Install

This package is available in the npm-registry. In order to use it simply install it with yarn (or npm):

yarn add moleculer-sharp

Usage

To make use of this Service, simply require it and create a new service:

const fs = require("fs");
let { ServiceBroker } = require("moleculer");
let SharpService = require("moleculer-sharp");

let broker = new ServiceBroker({ logger: console });

// Create a service
broker.createService({
    mixins: SharpService,
});

// Start server
broker.start()
    .then(() => broker.call('sharp.metadata',{url: 'https://pics.me.me/welcome-to-the-internet-ill-be-your-guide-28274277.png'}))
    .then(() => broker.call('sharp.stats',{url: 'https://pics.me.me/welcome-to-the-internet-ill-be-your-guide-28274277.png'}))
    .then(() => 
        broker.call('sharp.process',{url: 'https://pics.me.me/welcome-to-the-internet-ill-be-your-guide-28274277.png'}, {meta:
            steps: [
                ["resize", 200],
                ["rotate", 30, {"background": {"r": 0, "g": 0, "b": 0, "alpha": 0}}],
                "jpeg"
            ]
        }));

For a more indepth example checkout out the examples folder. It includes a docker-compose file, running docker-compose up will boot a broker with a sharp service and an API Gateway to invoke the actions of the sharp service. This project includes a published postman collection enabling you to quickly explore the service in your local environment.

Settings

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | No settings.

Actions

metadata

Fast access to (uncached) image metadata without decoding any compressed image data.

broker.call('sharp.metadata',{url: 'https://pics.me.me/welcome-to-the-internet-ill-be-your-guide-28274277.png'})

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | params | String, ReadableStream, Object | required | the image to acquire metadata for, can be a path, a stream or an object. If a path is given, this action will try to acquire a readable stream for the path. If an object is given, a http(s) stream will be acquired and the response body will be subject. For the location of the request, the url property will be used, while all other properties will be used as node-fetch-options |

Results

Type: PromiseLike.<(Object|Error)>

stats

Gather stats of an image

broker.call('sharp.stats',{url: 'https://pics.me.me/welcome-to-the-internet-ill-be-your-guide-28274277.png'})

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | params | String, ReadableStream, Object | required | the image to acquire stats for, can be a path, a stream or an object. If a path is given, this action will try to acquire a readable stream for the path. If an object is given, a http(s) stream will be acquired and the response body will be subject. For the location of the request, the url property will be used, while all other properties will be used as node-fetch-options |

Results

Type: PromiseLike.<(Object|Error)>

process

Processes an image. The action parameter indicates which image to process. The actual processing instructions have to be provided via the meta.steps property of the call. Any operation that is listed on the Sharp Documentation can be included as a step instruction. Here is an example:

broker.call('sharp.process',{url: 'https://pics.me.me/welcome-to-the-internet-ill-be-your-guide-28274277.png'}, {meta:
    steps: [
        ["resize", 200],
     ["rotate", 30, {"background": {"r": 0, "g": 0, "b": 0, "alpha": 0}}],
     "jpeg"
    ]
})

If your last step instructions is a toFile instructions, the transformation output will be written to disk, and the action will respond with meta information about the image. In any other case the action will respond with a readable stream for your to further process.

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | params | String, ReadableStream, Object | required | the image to process, can be a path, a stream or an object. If a path is given, this action will try to acquire a readable stream for the path. If an object is given, a http(s) stream will be acquired and the response body will be subject. For the location of the request, the url property will be used, while all other properties will be used as node-fetch-options |

Results

Type: PromiseLike.<(undefined|Error)>

Methods

acquireReadStream

Acquire a readable stream from a given source

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | source | String, ReadableStream, Object | required | can be a path, a stream or an object. If a path is given, this action will try to acquire a readable stream for the path. If an object is given, a http(s) stream will be acquired for the response body. For the location of the request, the url property will be used, while all other properties will be used as node-fetch-options |

Results

Type: PromiseLike.<(Stream|SharpStreamAcquisitionError|Error)>

bufferStream

Feed a Stream into a Buffer

Parameters

| Property | Type | Default | Description | | -------- | ---- | ------- | ----------- | | stream | ReadableStream | required | |

Results

Type: PromiseLike.<(Buffer|Error)>

Test

$ docker-compose exec package yarn test

In development with watching

$ docker-compose up

License

moleculer-sharp is available under the MIT license.

FOSSA Status