-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for image source as arraybuffer, buffer and blob
- Loading branch information
Showing
8 changed files
with
197 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## 2.0.0 | ||
|
||
- Add support for `arraybuffer`, `blob` and `buffer` as image source | ||
- Use `buffer-image-size` package instread of `probe-image-size` | ||
- Use `centra` package in nodejs to fetch image. | ||
|
||
## 1.0.2 | ||
|
||
- Initial Release | ||
|
||
```sh | ||
npm install @coderosh/image-size | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
import imageSize from '../src/browser' | ||
import axios from 'axios' | ||
|
||
it('imageSize:browser should return width and height', async () => { | ||
const size = await imageSize('https://ulka.js.org/logo.png') | ||
const imgUrl = 'https://ulka.js.org/logo.png' | ||
|
||
expect(size).toEqual({ height: 827, width: 738 }) | ||
describe('imageSize:browser', () => { | ||
beforeAll(() => { | ||
window.URL.createObjectURL = () => imgUrl | ||
}) | ||
|
||
it('should return width and height if src is url', async () => { | ||
const size = await imageSize(imgUrl) | ||
|
||
expect(size).toEqual({ height: 827, width: 738 }) | ||
}) | ||
|
||
it('should return height and width if src is arraybuffer', async () => { | ||
const res = await axios.get(imgUrl, { responseType: 'arraybuffer' }) | ||
|
||
const size = await imageSize(res.data) | ||
|
||
expect(size).toEqual({ height: 827, width: 738 }) | ||
}) | ||
|
||
it('should return height and width if src is Blob', async () => { | ||
const res = await axios.get(imgUrl, { responseType: 'blob' }) | ||
|
||
const size = await imageSize(res.data) | ||
|
||
expect(size).toEqual({ height: 827, width: 738 }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
import axios from 'axios' | ||
import imageSize from '../src/' | ||
import centra from 'centra' | ||
|
||
test('imageSize:node should return width and height', async () => { | ||
const size = await imageSize('https://ulka.js.org/logo.png') | ||
expect(size).toEqual({ height: 827, width: 738 }) | ||
const imgUrl = 'https://ulka.js.org/logo.png' | ||
|
||
describe('imageSize:node', () => { | ||
it('should return width and height if src is string', async () => { | ||
const size = await imageSize('https://ulka.js.org/logo.png') | ||
expect(size).toEqual({ height: 827, width: 738 }) | ||
}) | ||
|
||
it('should return height and width if src is arraybuffer', async () => { | ||
const res = await axios.get(imgUrl, { responseType: 'arraybuffer' }) | ||
const size = await imageSize(res.data) | ||
expect(size).toEqual({ height: 827, width: 738 }) | ||
}) | ||
|
||
it('should return height and width if src is buffer', async () => { | ||
const buffer = await centra(imgUrl) | ||
.send() | ||
.then((res) => res.body) | ||
|
||
const size = await imageSize(buffer) | ||
expect(size).toEqual({ height: 827, width: 738 }) | ||
}) | ||
}) |
Oops, something went wrong.