4.0.0 • Published 3 months ago

jinie v4.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Jinie

✨ Simple Image Editing & Compression Tool ✨

Easily enhance and optimize images before upload with Jinie. Crop, pan, scale, and rotate with a built-in compression feature to compress images to the target size. 🚀

Installation 🚀

To install the Jinie package, you can use npm:

npm install jinie

Usage 🛠️

Jinie need to be initialized only once at the top.

ReactJS example

import Jinie from 'jinie'
import 'jinie/dist/styles.css'

function App() {
  return (<div>
    {/* Initialize Jinie */}
    <Jinie />

    ..

    <BrowserRouter>
      <Routes>
        <Route .. />
        ..
      </Routes>
    </BrowserRouter>
  </div>)
}

createRoot(document.getElementById('root') as HTMLElement).render(<App />)

Here's a basic example of how to use Jinie to edit images:

import Jinie from 'jinie'

..

// Upload and crop image on init
<button
  onClick={() =>
    Jinie.init({
      accept: 'image/jpeg',
      onReady: result => {
        console.log(result) // Cropped image blob
      }
    })
  }
>
  Upload Image
</button>

// Or provide an image to crop in init
<input
  type='file'
  accept='image/jpeg'
  onChange={async (e) => {
    const img = e.target.files[0]
    Jinie.init({
      img,
      onResult: ({ code, img }) => {
        console.log(code, img)
        if (img) setImgURL(window.URL.createObjectURL(img))
      }
    })
  }}
/>
ArgumentTypeUsageDefault
onResultFunctionResult callback
img?BlobSource image, if not provded, request image on init
accept?StringAllowed mime types, only works when img not providedimage/jpeg,image/png
aspectRatio?NumberCrop box aspect ratio
icon?NumberOutput png filefalse
fill?NumberBackground colorTransparent for icon & white for jpg
minWidth?NumberMin image width required else cancel
minHeight?NumberMin image height required else cancel
minSize?NumberMin image size required else cancel
maxSize?NumberMax output size

Result codes

CodeImageNote
OKtrueOkay
MAX_COMPRESSIONtrueImage max compressed, but still greater than max size argument
CANCELEDfalseUser clicked on cancel
MIN_WIDTH_FAILfalseImage width is less than the min image argument
MIN_HEIGHT_FAILfalseImage height is less than the min image argument
MIN_SIZE_FAILfalseImage size is less than the min size argument
COMPRESSION_ERRORfalseError occurred while compressing the image

Jinie.CompressionLoop exports the Compression Loop package which is used to compress the image to the target size. It can be used alone to compress images without opening the Jinie editor.

Dark theme setup

While initializing Jinie

<Jinie theme='dark' />

or automatic theme detection with body[data-theme]="dark"

<html>
  <head>
    ..
  </head>

  <body data-theme="dark">
    ..
  </body>
</html>

License 📜

This package is open-source and available under the MIT License.

Contributing 🙌

Contributions to the Jinie package are welcome! If you have any ideas, improvements, or bug fixes, please submit a pull request or open an issue.

Authors 🖋️

Developed & maintained by neilveil

4.0.0

3 months ago

3.2.0

4 months ago

3.0.3

7 months ago

3.1.1

7 months ago

3.0.2

7 months ago

3.1.0

7 months ago

3.0.1

7 months ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago