Skip to content

Commit

Permalink
Merge pull request #4 from crisconru/dev
Browse files Browse the repository at this point in the history
v0.0.1
  • Loading branch information
crisconru authored Feb 25, 2024
2 parents 1e1fb7a + 337d641 commit e86d178
Show file tree
Hide file tree
Showing 36 changed files with 8,449 additions and 9,528 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
31 changes: 0 additions & 31 deletions .github/workflows/node.js.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: publish

on: push

jobs:
test:
name: 🧪 Test
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- name: 👍 Checkout
uses: actions/checkout@v3

- name: ❇️ Setup node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: 📥 Install Dependencies
run: npm install

- name: 🧑‍🔬 Tests
run: npm run test

publish:
name: 🚀 Publish
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'

steps:
- name: 👍 Checkout
uses: actions/checkout@v3

- name: ❇️ Setup node.js
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'

- name: 📥 Install Dependencies
run: npm install

- name: 🛠️ Build
run: npm run build

- name: 🚀 Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 6 additions & 1 deletion .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Custom
.vscode
.idea
.DS_Store
lib/

# Logs
logs
*.log
Expand Down Expand Up @@ -59,7 +65,6 @@ typings/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
Expand Down
Empty file modified LICENSE
100644 → 100755
Empty file.
86 changes: 61 additions & 25 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,64 @@

[![Node.js CI](https://github.com/crisconru/splitea/actions/workflows/node.js.yml/badge.svg)](https://github.com/crisconru/splitea/actions/workflows/node.js.yml)

Is a tool to split images. The code is based on [image-splitter](https://github.com/achimoraites/image-splitter) code.

The idea is that you tell to the lib what source image to use and:

- N images per row and M images per colum -> You get image splitted into N x M images.
- N px per row and M px per colum -> You get image splitted into images with N x M px.

Then you tell if you want to store them and how to return data.

Inputs are two arguments:

1. `image` -> Source image => `String` (local file or url) | `Buffer` | `Jimp Object`
2. `options` -> JSON with next properties:
1. `mode` -> Split mode => `grid` (by default) | `vertical` | `horizontal`
2. `tiles` -> JSON with properties related to the slices or commonly known as tiles
1. `rows` -> Number of rows
2. `columns` -> Number of columns
3. `width` -> Width in pixels per tile
4. `height` -> Height in pixels per tile
5. `unique` -> If you need all tiles or non-repeated => `false` (all tiles by default) | `true` (non-repeated tiles)
3. `output` -> JSON with properties related to the output / return data and how store it
1. `data` -> Type of data to be returned => `buffer` (default) | `path` (local path)
2. `path` -> Local path to save the tiles
3. `name` -> Preffix name to save the tiles
4. `extension` -> Supported extension to save tiles => `jpg` | `png` | `bmp` | `gif` | `tiff`
It is a tool to split images into tiles or pieces. The idea is based on the project [image-splitter](https://github.com/achimoraites/image-splitter).

It has just one entry point with three arguments and the response is an array of tiles:

- `image`: The image to split. It is a string path or a buffer
- `tiles`: All the information to create the tiles
- `mode`: How to cut the images
- `rows` / `height`: Number of rows to be cut or height in px of each tile
- `columns` / `width`: Number of columns to be cut or width in px of each tile
- `unique`: Options to specify if you just want tiles not repeated
- `distance`: Max distance between tiles to be filtered
- `difference`: Max difference between tiles to be filtered
- `requirement`: Condition to be filtered, one of them or both
- `output`: Information for the created tiles
- `response`: Type of output, an array of Buffer (default) or the path of each tile
- `store`: Information if you want to store the tiles in the computer or not
- `path`: Where to store
- `name`: Filename pattern
- `extension`: Extension of the tiles

For the tiles there are only these possible combinations:

- `mode` = `"horizontal"` + (`columns` | `width`)
- `mode` = `"vertical"` + (`rows` | `height`)
- `mode` = `"grid"` + (`columns` + `rows` | `width` + `height`)

`columns` and `rows` are natural number while `width` and `height` are in pixels.

For the output the default type is buffer and it is not stored. If you want to store the tiles in the computer you'll have to add store object.

If you select response as `"path"` you have to add store object too.

```typecript
import { Splitea } from splitea
type Image = string | Buffer
type Tiles = {
mode: "horizontal" | "vertical" | "grid",
rows?: number,
columns?: number,
width?: number,
height?: number,
unique?: {
distance: number,
difference: number,
requirement: "one" | "both"
}
}
type Output = {
response: "buffer" | "path",
store?: {
path: string,
name: string,
extension?: "jpg" | "jpeg" | "png" | "bmp" | "gif" | "tiff"
}
}
const tiles: Promise<Image[]> = await Splitea(image: Image, tiles: Tiles, output: Output)
```
Binary file removed examples/Ericsatie.jpg
Binary file not shown.
5 changes: 0 additions & 5 deletions jest.config.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/index.js

This file was deleted.

Loading

0 comments on commit e86d178

Please sign in to comment.