Skip to content

Commit

Permalink
Added types
Browse files Browse the repository at this point in the history
  • Loading branch information
flameface committed Feb 17, 2024
1 parent 95c1d67 commit 0759e80
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 23 deletions.
Binary file removed assets/cropped-image.png
Binary file not shown.
Binary file removed assets/example.png
Binary file not shown.
Binary file added examples/cropped-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { cropImage } = require("cropify");
const fs = require("fs")

const imagePath = 'https://th.bing.com/th/id/OIGP.914kwCtAqWQ7Lkx5hT2B?pid=ImgGn';

const cropX = 0;
const cropY = 0;
const cropWidth = 1280;
const cropHeight = 720;
const borderRadius = 80;

cropImage({
imagePath: imagePath,
x: cropX,
y: cropY,
width: cropWidth,
height: cropHeight,
borderRadius: borderRadius,
cropCenter: true
}).then(x => {
fs.writeFileSync("cropped-image.png", x);
});
4 changes: 1 addition & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ interface cropOption {
cropCenter?: boolean
}

declare function cropImage(options: cropOption): Promise<Buffer>;

export { cropImage }
export declare function cropImage(options: cropOption): Promise<Buffer>;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function cropImage({
// Draw image
ctx.drawImage(image, x, y, scaledWidth, scaledHeight);

return canvas.toDataURL("image/png")
return canvas.toBuffer("image/png");
} catch (e) {
throw new Error(e.message)
}
Expand Down
28 changes: 25 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
"name": "cropify",
"types": "./index.d.ts",
"description": "Crop and round image corners seamlessly.",
"version": "1.0.5",
"version": "1.0.7",
"main": "index.js",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"files": [
"index.js",
"index.d.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -23,16 +27,14 @@
"dependencies": {
"@napi-rs/canvas": "^0.1.44"
},
"devDependencies": {},
"devDependencies": {
"@types/node": "^20.11.19"
},
"repository": {
"type": "git",
"url": "https://github.com/unburn/cropify.git"
},
"bugs": {
"url": "https://github.com/unburn/cropify/issues"
},
"funding": {
"type": "githubsponser",
"url": "https://github.com/sponsors/flameface"
}
}
42 changes: 32 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
## About
**Cropify** helps to crop and round image corners seamlessly.
<img src="https://ik.imagekit.io/unburn/Cropify.svg"/>

## Features
<p align="center">Cropify helps to crop and round image corners seamlessly.</p>

<p align="center">
<a href="https://github.com/unburn/cropify"><b>Github</b></a> •
<a href="https://discord.gg/66uGX7t4ww"><b>Support</b></a>
</p>

<div align="center">

[![NPM Version](https://img.shields.io/npm/v/cropify?style=flat-square&color=%2300ADD3)](https://www.npmjs.com/package/cropify)
[![NPM Downloads](https://img.shields.io/npm/dw/cropify?style=flat-square&color=%2300ADD3)](https://www.npmjs.com/package/cropify)
[![NPM License](https://img.shields.io/npm/l/cropify?style=flat-square&color=%2300ADD3)](https://github.com/unburn/cropify/blob/main/LICENCE)
[![GitHub Repo stars](https://img.shields.io/github/stars/unburn/cropify?style=flat-square&color=%2300ADD3)](https://github.com/unburn/cropify)

</div>

<div align="center">
<a href="https://github.com/sponsors/flameface"><img src="https://ik.imagekit.io/unburn/SupportCropify.svg"/></a>
</div>

# Features
- Crop images with precision using the Canvas API.
- Optional support for rounding corners with a customizable border radius.
- Designed for simplicity and performance.
- Upscale and cover image.

## Installation
# Installation
```
npm install cropify
```

## Usage
# Usage
```javascript
const { cropImage } = require("cropify");
const fs = require("fs")

const imagePath = 'https://storage.googleapis.com/pai-images/8c27ed6e3c85463a8db958ecb596594e.jpeg';
const imagePath = 'https://th.bing.com/th/id/OIGP.914kwCtAqWQ7Lkx5hT2B?pid=ImgGn';

const cropX = 0;
const cropY = 0;
Expand All @@ -31,14 +50,17 @@ cropImage({
y: cropY,
width: cropWidth,
height: cropHeight,
borderRadius: borderRadius
borderRadius: borderRadius,
cropCenter: true
}).then(x => {
fs.writeFileSync("cropped-image.png", x);
});
```

> **Note**: The image used in this example is generated using DALL-E
## Output
![example](./assets/example.png)
![example](https://ik.imagekit.io/unburn/CropifyExample.svg)

---
If you need help or want some features to be added, join our official [discord](https://discord.com/invite/qDysF95NWh) community.
# Licence
[MIT](https://github.com/unburn/cropify/blob/main/LICENCE)

0 comments on commit 0759e80

Please sign in to comment.