# smart-image-saver

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

Latest version **1.0.2** (published 2023-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install smart-image-saver
pnpm add smart-image-saver
yarn add smart-image-saver
bun add smart-image-saver
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-04-27 |
| First published | 2023-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ericbellamy |
| Maintainers | eric.bellamy |
| Keywords | tiny, npm, package, image, images, save, saver, download, downloader, image converting |

## Links

- npm: https://www.npmjs.com/package/smart-image-saver
- Repository: https://github.com/ericbellamy/smart-image-saver
- Homepage: https://github.com/ericbellamy/smart-image-saver#readme
- Issues: https://github.com/ericbellamy/smart-image-saver/issues
- npm.io page: https://npm.io/package/smart-image-saver

## Dependencies (6)

- [http](https://npm.io/package/http.md) ^0.0.1-security
- [path](https://npm.io/package/path.md) ^0.12.7
- [https](https://npm.io/package/https.md) ^1.0.0
- [sharp](https://npm.io/package/sharp.md) ^0.32.0
- [colors](https://npm.io/package/colors.md) ^1.4.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^11.1.1

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-04-27
- 1.0.1 — 2023-04-26

## 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.

&nbsp;

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

&nbsp;

## Required Parameters

```javascript
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"`

&nbsp;

### Destination name

```javascript
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"`

&nbsp;


### Destination image type
```javascript
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"`


&nbsp;

&nbsp;

&nbsp;





# Extra Case Handling

### Ignores everything after the folder path
```javascript
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest"
});
```
```javascript
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest/"
});
```
```javascript
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"`


&nbsp;

### Ignores everything except the extensionless name of the file

```javascript
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest",
    name: "example"
});
```
```javascript
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest",
    name: "example.png"
});
```
```javascript
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"`


&nbsp;

### Type handling

```javascript
await saveImage({
    url: "http://someurl.com/image.jpg",
    path: "/path/to/dest/",
    type: "webp"
});
```
```javascript
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"`

---
_Source: https://npm.io/package/smart-image-saver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
