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

smart-image-saver

v1.0.2

Published

Convenience package for saving images locally. Supports image converting with sharp, automatic output folder creation & simplified handling of destination paths.

Downloads

5

Readme

smart-image-saver

NPM package for saving images locally. Supports image converting with sharp, automatic destination folder creation & simplified handling of destination paths.

This package mainly saves you the code of converting images yourself, getting the destination folder path & ensuring it exists, and having to modify the destination file type for conversions.

 

const saveImage = require('smart-image-saver');

 

Required Parameters

await saveImage({
    url: "http://someurl.com/path/to/dest/image.jpg",
    path: "/path/to/dest/image.jpg",
});

The most basic usage is providing a source url, and a local path.

This example results in a file saved with the path: "/path/to/dest/image.jpg"

 

Destination name

await saveImage({
    url: "http://someurl.com/path/to/dest/image.jpg",
    path: "/path/to/dest/image.jpg",
    name: "example",
});

If a file name is provided, it will override the file name found in the source url.

This example results in a file saved with the path: "/path/to/dest/example.jpg"

 

Destination image type

await saveImage({
    url: "http://someurl.com/path/to/dest/image.jpg",
    path: "/path/to/dest/image.jpg",
    name: "example",
    type: "webp"
});

If a file type is provided, it will automatically convert the image to that type, and override the file type found in the source url.

This example results in a file saved with the path: "/path/to/dest/example.webp"

 

 

 

Extra Case Handling

Ignores everything after the folder path

await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest"
});
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest/"
});
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest/ignored.jpg"
});

The package automatically ignores any file name in the path, appending the name & type.

Any of these examples will result in a file saved with the path: "/path/to/dest/image.jpg"

 

Ignores everything except the extensionless name of the file

await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest",
    name: "example"
});
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest",
    name: "example.png"
});
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest/ignored.jpg",
    name: "/path/to/dest/all/of/this/will/be/ignored/example.png"
});

The package automatically ignores any file path & file type found in the file name.

These examples will result in a file saved with the path: "/path/to/dest/example.jpg"

 

Type handling

await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest/",
    type: "webp"
});
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest/ignored.jpg",
    type: "webp"
});

If a file type value is provided, the saved image will be converted to that file type and saved with that file extension.

Both of these example will result in a file saved with the path: "/path/to/dest/image.webp"