Skip to content

Commit

Permalink
cjs to mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Coxxs committed Aug 29, 2021
1 parent 232edbb commit 205e54c
Show file tree
Hide file tree
Showing 12 changed files with 2,082 additions and 128 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ npm install --save image-hide
```

```javascript
const fs = require('fs')
const hide = require('image-hide')
import { promises as fs } from 'fs'
import hide from 'image-hide'

// Size (width & height) of these images should be same.
let imageA = fs.readFileSync('a.png')
let imageB = fs.readFileSync('b.png')
let imageA = await fs.readFile('a.png')
let imageB = await fs.readFile('b.png')

fs.writeFileSync('result.png', Buffer.from(hide(imageA, imageB)))
await fs.writeFile('result.png', Buffer.from(hide(imageA, imageB)))
```
8 changes: 3 additions & 5 deletions index.js → index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const decode = require('image-decode')
const encode = require('image-encode')
import decode from 'image-decode'
import encode from 'image-encode'

function hide(foreground, background) {
export default function hide(foreground, background) {
let image_a = decode(foreground)
let image_b = decode(background)
if (image_a.height != image_b.height || image_a.width !== image_b.width) {
Expand Down Expand Up @@ -30,5 +30,3 @@ function hide(foreground, background) {
function getPixelAvg(r, g, b, a, bg = 0) {
return (r + g + b) / 3 * (a / 255) + bg * (1 - a / 255)
}

module.exports = hide
Loading

0 comments on commit 205e54c

Please sign in to comment.