Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.1 #4

Merged
merged 64 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b9c36d3
all tests with mode + tiles
crisconru Jul 12, 2022
dcb2336
integrate mode into tiles property
crisconru Jul 13, 2022
9d2282f
tested output data
crisconru Jul 13, 2022
2107bdb
Output options - parse data + path
crisconru Jul 15, 2022
0aa3a55
test name but not if it is an invalid os filename
crisconru Jul 17, 2022
63476bb
parse extension and tested
crisconru Jul 17, 2022
648b0d3
Complete tested filename without dependencies
crisconru Jul 22, 2022
0cd15cb
all splitea almost tested. Needs unique and store
crisconru Aug 28, 2022
6b36d01
test uniques completed
crisconru Oct 9, 2022
651ba7a
updating deps
crisconru Aug 3, 2023
e3b9b2c
changing jest for vitest
crisconru Aug 3, 2023
6f1638e
typescript config
crisconru Aug 3, 2023
d80b752
vitest
crisconru Aug 3, 2023
867b015
main repo files
crisconru Aug 3, 2023
a3ddd94
state of the art, tests are passing
crisconru Aug 3, 2023
562413d
update github actions
crisconru Aug 3, 2023
5bb14d5
removed lint
crisconru Aug 3, 2023
23ee44d
publish just with node 18
crisconru Aug 3, 2023
57e7c45
zod added
crisconru Aug 6, 2023
3796174
options to editorconfig
crisconru Aug 6, 2023
e21f871
added zod to project and removed parsers
crisconru Aug 6, 2023
5b96d30
reorder files and check tiles completed
crisconru Aug 6, 2023
1696115
checktiles tested
crisconru Aug 6, 2023
1e0c9e1
refactor testing
crisconru Aug 6, 2023
6e1e425
extracting unique logic to image file
crisconru Aug 6, 2023
464ecc3
output tested
crisconru Aug 7, 2023
8bd633b
utils tested
crisconru Aug 7, 2023
10ea42a
types with schemas
crisconru Aug 7, 2023
ac4be2c
refactor tiles to not operate with jimp
crisconru Aug 10, 2023
67a0c37
jimp operations moved to image.ts
crisconru Aug 10, 2023
86cda71
tested image
crisconru Aug 15, 2023
624bf45
tested tiles
crisconru Aug 15, 2023
97f9aec
output tested
crisconru Aug 15, 2023
46e4c66
create path if not exists
crisconru Aug 15, 2023
f6648b7
moving check logic to schemas
crisconru Sep 2, 2023
45db614
adding logic to schemas for tiles cut
crisconru Sep 3, 2023
9191ae6
tiles full tested and independant from images
crisconru Sep 3, 2023
edca669
images tested completely
crisconru Sep 3, 2023
a8e1619
tested Output schemas
crisconru Sep 3, 2023
8b96c51
tested output schemas
crisconru Sep 3, 2023
4bc475d
output completely tested
crisconru Sep 3, 2023
0b42301
fix types to remove temp folders + files
crisconru Sep 3, 2023
7510ee9
migrated schemas and types to valibot from zod
crisconru Feb 23, 2024
5a349fd
set ts options
crisconru Feb 23, 2024
2a4b9b7
removing build from repo
crisconru Feb 23, 2024
4cd6e7b
deleted unnecessary files
crisconru Feb 23, 2024
7e3c46c
removed build
crisconru Feb 23, 2024
8975758
tests passed
crisconru Feb 23, 2024
48974b8
add better error msg if it is a valibot error
crisconru Feb 25, 2024
3425bfc
schemas tested
crisconru Feb 25, 2024
1774191
image tested
crisconru Feb 25, 2024
20d83e2
output tested
crisconru Feb 25, 2024
1604006
splitea tested
crisconru Feb 25, 2024
31d4229
forgot to commit before
crisconru Feb 25, 2024
ced92f6
tiles tested
crisconru Feb 25, 2024
188e950
named export instead of default
crisconru Feb 25, 2024
009ab63
changed deprecated nodejs rmdir to rm
crisconru Feb 25, 2024
8f7b99f
adding better error
crisconru Feb 25, 2024
7892fde
refactor to pass the build
crisconru Feb 25, 2024
5e7d03c
adding types to filename-reserved-regex
crisconru Feb 25, 2024
1349d83
removed enable option in output.unique because is too redundant
crisconru Feb 25, 2024
429f619
full readme with final api
crisconru Feb 25, 2024
a4672a9
non node lts deprecated versions
crisconru Feb 25, 2024
337d641
alpha version is ready
crisconru Feb 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading