mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 00:37:19 +00:00
Change 'encodedAs' to 'encodedWith'
This commit is contained in:
@@ -81,7 +81,7 @@ When you have encoded an image, you normally want to write it to a file.
|
|||||||
This example takes an image that has been encoded as a `jpg` and writes it to a file:
|
This example takes an image that has been encoded as a `jpg` and writes it to a file:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const rawEncodedImage = (await image.encodedAs.jpg).binary;
|
const rawEncodedImage = (await image.encodedWidth.mozjpeg).binary;
|
||||||
|
|
||||||
fs.writeFile('/path/to/new/image.jpg', rawEncodedImage);
|
fs.writeFile('/path/to/new/image.jpg', rawEncodedImage);
|
||||||
```
|
```
|
||||||
@@ -91,8 +91,8 @@ This example iterates through all encoded versions of the image and writes them
|
|||||||
```js
|
```js
|
||||||
const newImagePath = '/path/to/image.'; //extension is added automatically
|
const newImagePath = '/path/to/image.'; //extension is added automatically
|
||||||
|
|
||||||
for(const [extension, encodedImage] of Object.entries(image.encodedAs)){
|
for(const encodedImage of Object.values(image.encodedWith)){
|
||||||
fs.writeFile(newImagePath + extension, (await encodedImage).binary);
|
fs.writeFile(newImagePath + (await encodedImage).extension, (await encodedImage).binary);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -119,11 +119,11 @@ console.log(await image.decoded);
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Information about an encoded image can be found at `Image.encodedAs[extension]`. It looks something like this:
|
Information about an encoded image can be found at `Image.encodedWith[encoderName]`. It looks something like this:
|
||||||
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
console.log(await image.encodedAs.jxl);
|
console.log(await image.encodedWith.jxl);
|
||||||
// Returns:
|
// Returns:
|
||||||
{
|
{
|
||||||
optionsUsed: {
|
optionsUsed: {
|
||||||
@@ -139,6 +139,7 @@ console.log(await image.encodedAs.jxl);
|
|||||||
9, 10, 10, 9,
|
9, 10, 10, 9,
|
||||||
... //the entire raw encoded image
|
... //the entire raw encoded image
|
||||||
],
|
],
|
||||||
|
extension: 'jxl',
|
||||||
size: 1266975 //bytes
|
size: 1266975 //bytes
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ async function encodeImage({
|
|||||||
return {
|
return {
|
||||||
optionsUsed,
|
optionsUsed,
|
||||||
binary,
|
binary,
|
||||||
|
extension: encoders[encName].extension,
|
||||||
size: binary.length,
|
size: binary.length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -117,7 +118,7 @@ class Image {
|
|||||||
constructor (workerPool, file) {
|
constructor (workerPool, file) {
|
||||||
this.workerPool = workerPool;
|
this.workerPool = workerPool;
|
||||||
this.decoded = workerPool.dispatchJob({operation: 'decode', file});
|
this.decoded = workerPool.dispatchJob({operation: 'decode', file});
|
||||||
this.encodedAs = {};
|
this.encodedWith = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,7 +166,7 @@ class Image {
|
|||||||
encRef.defaultEncoderOptions,
|
encRef.defaultEncoderOptions,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
this.encodedAs[encRef.extension] = this.workerPool.dispatchJob({
|
this.encodedWith[encName] = this.workerPool.dispatchJob({
|
||||||
operation: 'encode',
|
operation: 'encode',
|
||||||
bitmap,
|
bitmap,
|
||||||
encName,
|
encName,
|
||||||
@@ -178,7 +179,7 @@ class Image {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await Promise.all(Object.values(this.encodedAs));
|
await Promise.all(Object.values(this.encodedWith));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ async function processFiles(files) {
|
|||||||
.then(async () => {
|
.then(async () => {
|
||||||
jobsFinished++;
|
jobsFinished++;
|
||||||
const outputPath = path.join(program.opts().outputDir, program.opts().suffix + path.basename(originalFile, path.extname(originalFile)));
|
const outputPath = path.join(program.opts().outputDir, program.opts().suffix + path.basename(originalFile, path.extname(originalFile)));
|
||||||
for(const [extension, output] of Object.entries(image.encodedAs)){
|
for(const output of Object.values(image.encodedWith)){
|
||||||
const outputFile = `${outputPath}.${extension}`;
|
const outputFile = `${outputPath}.${(await output).extension}`;
|
||||||
await fsp.writeFile(outputFile, (await output).binary);
|
await fsp.writeFile(outputFile, (await output).binary);
|
||||||
results.get(image).outputs.push(
|
results.get(image).outputs.push(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
|
|||||||
Reference in New Issue
Block a user