Comparing version 0.1.4 to 0.1.5
@@ -6,21 +6,17 @@ import { ResizeOptions, Sharp, SharpOptions } from "sharp"; | ||
export declare type PngOrBmpBuffer = Buffer; | ||
export declare type SharpBuffer = Buffer; | ||
export declare type ImageType = "png" | "bmp"; | ||
export declare interface Hotspot { | ||
x: number; | ||
y: number; | ||
} | ||
/** | ||
* ICO icon data | ||
* @param width - width of the image, maximum of 256 | ||
* @param height - height of the image, maximum of 256 | ||
* @param colors - number of colors | ||
* @param colorPlanes - color planes of an ICO image | ||
* @param bitsPerPixel - bits per pixel of an ICO image | ||
* @param horizontalHotspot - horizontal hotspot of a CUR image | ||
* @param verticalHotspot - vertical hotspot of a CUR image | ||
* @param imageSize - (interal) size of imageData's buffer | ||
* @param imageOffset - (interal) offset start of the image data | ||
* @param imageType - "png" or "bmp" | ||
* @param imageData - original image data of the icon | ||
* @param data - sharp image data | ||
* @param bmpData - if imageType is "bmp", will contains the bmp image data | ||
* @param image - instance of sharp | ||
* @param width - The width of the image, in pixels | ||
* @param height - The height of the image, in pixels | ||
* @param type - The type of image, will be one of `bmp` or `png` | ||
* @param bpp - The color depth of the image as the number of bits used per pixel | ||
* @param data - The data of the image, format depends on type | ||
* @param hotspot - If the image is a cursor (.cur), this is the hotspot | ||
* @public | ||
@@ -31,13 +27,6 @@ */ | ||
height: number; | ||
colors: number; | ||
colorPlanes: number; | ||
bitsPerPixel: number; | ||
horizontalHotspot: number; | ||
verticalHotspot: number; | ||
imageSize: number; | ||
imageOffset: number; | ||
imageType: ImageType; | ||
imageData: PngOrBmpBuffer; | ||
data: SharpBuffer; | ||
bmpData?: BmpData; | ||
type: ImageType; | ||
bpp: number; | ||
data: Uint8Array; | ||
hotspot: null | Hotspot; | ||
image?: Sharp; | ||
@@ -44,0 +33,0 @@ } |
22
index.js
const fs = require("fs"); | ||
const sharp = require("sharp"); | ||
const ico = require("ico-endec"); | ||
const bmp = require("sharp-bmp"); | ||
const decodeIco = require("decode-ico"); | ||
const icoEndec = require("ico-endec"); | ||
function decode(buffer) { | ||
return ico.decode(buffer).map((icon) => { | ||
if (icon.imageType === "png") { | ||
return Object.assign(icon, { data: icon.imageData }); | ||
} else { | ||
const bmpData = bmp.decode(icon.imageData); | ||
return Object.assign(icon, { | ||
data: bmpData.data, | ||
bmpData, | ||
}); | ||
} | ||
}); | ||
return decodeIco(buffer); | ||
} | ||
function encode(bufferList) { | ||
return ico.encode(bufferList); | ||
return icoEndec.encode(bufferList); | ||
} | ||
@@ -26,5 +16,5 @@ | ||
const buffer = typeof input === "string" ? fs.readFileSync(input) : input; | ||
return decode(buffer).map((icon) => { | ||
return decodeIco(buffer).map((icon) => { | ||
const image = | ||
icon.imageType === "png" | ||
icon.type === "png" | ||
? sharp(icon.data, options || {}) | ||
@@ -31,0 +21,0 @@ : sharp(icon.data, { |
{ | ||
"name": "sharp-ico", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "ICO encoder and decoder for sharp base on ico-endec.", | ||
@@ -35,6 +35,6 @@ "scripts": { | ||
"dependencies": { | ||
"sharp": "*", | ||
"decode-ico": "*", | ||
"ico-endec": "*", | ||
"sharp-bmp": "^0.1.5" | ||
"sharp": "*" | ||
} | ||
} |
# sharp-ico | ||
ICO encoder and decoder for [sharp](https://www.npmjs.com/package/sharp) base on [ico-endec](https://www.npmjs.com/package/ico-endec). | ||
ICO encoder and decoder for [sharp](https://www.npmjs.com/package/sharp) base on [ico-endec](https://www.npmjs.com/package/ico-endec) (for encode) and [decode-ico](https://www.npmjs.com/package/decode-ico) (for decode). | ||
@@ -103,11 +103,11 @@ ## Install | ||
- `width` number - width of the image, maximum of `256`. | ||
- `height` number - height of the image, maximum of `256`. | ||
- `imageSize` number - (interal) size of imageData's buffer. | ||
- `imageType` string - `"png"` or `"bmp"`. | ||
- `imageData` Buffer - Original image data of the icon. | ||
- `data` Buffer - sharp image data. | ||
- `bmpData` Object - If `imageType` is `"bmp"`, will contains the [bmp image data](https://github.com/shaozilee/bmp-js#decode-bmp). | ||
- ... (See `index.d.ts` for more detail.) | ||
- `width` number - The width of the image, in pixels. | ||
- `height` number - The height of the image, in pixels. | ||
- `type` string - The type of image, will be one of `bmp` or `png`. | ||
- `data` Uint8Array - The data of the image, format depends on type, see below. | ||
- `bpp` number - The color depth of the image as the number of bits used per pixel. | ||
- `hotspot` null | { x: number, y: number } - If the image is a cursor (.cur), this is the hotspot. | ||
The format of the `data` parameter depends on the `type` of image. When the image is of type `bmp`, the data array will hold raw pixel data in the RGBA order, with integer values between 0 and 255 (included). When the type is `png`, the array will be png data. | ||
```js | ||
@@ -122,13 +122,12 @@ const fs = require("fs"); | ||
icons.forEach((icon) => { | ||
if (icon.imageType === "png") { | ||
sharp(icon.data).toFile(`output-${icon.width}x${icon.height}.png`); | ||
} else { // icon.imageType === "bmp" | ||
const image = sharp(icon.data, { | ||
raw: { | ||
width: icon.width, | ||
height: icon.height, | ||
channels: 4, | ||
}, | ||
}).toFile(`output-${icon.width}x${icon.height}.jpg`); | ||
} | ||
const image = icon.type === "png" | ||
? sharp(icon.data) | ||
: sharp(icon.data, { | ||
raw: { | ||
width: icon.width, | ||
height: icon.height, | ||
channels: 4, | ||
}, | ||
}); | ||
image.toFile(`output-${icon.width}x${icon.height}.png`); | ||
}); | ||
@@ -174,1 +173,7 @@ ``` | ||
- `sharpsToIco` support `sizes` option | ||
### 0.1.5 | ||
- Use [decode-ico](https://www.npmjs.com/package/decode-ico) instead of [ico-endec](https://www.npmjs.com/package/ico-endec) for decoding to support transparent bmp icons. | ||
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
177
11497
144
3
+ Addeddecode-ico@*
+ Added@canvas/image-data@1.0.0(transitive)
+ Addeddecode-bmp@0.2.1(transitive)
+ Addeddecode-ico@0.4.1(transitive)
+ Addedto-data-view@1.1.0(transitive)
- Removedsharp-bmp@^0.1.5
- Removedbmp-js@0.1.0(transitive)
- Removedsharp-bmp@0.1.5(transitive)