Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lossless compression module #1603

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Modules.js
Expand Up @@ -32,6 +32,7 @@ module.exports = {
'grid-overlay': require('./modules/GridOverlay'),
'import-image': require('./modules/ImportImage'),
'minify-image': require('./modules/MinifyImage'),
daemon1024 marked this conversation as resolved.
Show resolved Hide resolved
'lossless-compress-image': require('./modules/LosslessCompression'),
// 'invert': require('image-sequencer-invert'),
'invert': require('./modules/Invert'),
'ndvi': require('./modules/Ndvi'),
Expand All @@ -48,4 +49,4 @@ module.exports = {
'tint': require('./modules/Tint'),
'webgl-distort': require('./modules/WebglDistort'),
'white-balance': require('./modules/WhiteBalance')
};
};
44 changes: 44 additions & 0 deletions src/modules/LosslessCompression/Module.js
@@ -0,0 +1,44 @@
module.exports = function LosslessCompress(options, UI) {
function draw(input, callback, progressObj) {
const compress_images = require('compress-images');
compress_images(
'input',
'results/',
{ compress_force: false, statistic: true, autoupdate: true },
false,
{ jpg: { engine: 'jpegoptim', command: ['--all-progressive', '-d'] } },
{ png: { engine: 'optipng' } },
function(err, completed) {
if (completed === true) {
var reader = new FileReader();
reader.readAsDataURL('results/**/*');
reader.onloadend = function() {
base64data = reader.result;
output(null, base64data, input.format, false);
if (callback) callback();
return;
};
}
}
);
progressObj.stop(true);
progressObj.overrideFlag = true;

var step = this;

function output(image, datauri, mimetype, wasmSuccess) {
step.output = {
src: datauri,
format: mimetype,
wasmSuccess,
useWasm: options.useWasm
};
}
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work? What do you get as an output after running this? @daemon1024

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to insert the lossless-compression as a step. I can't seem to understand how to pass the input in the function. The parameter required there is path to the file, but the incoming data is a dataURI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://hastebin.com/bakopiwino.coffeescript
This is the error I get when i run npm run test-all

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't run the test right now. Tests are to be ran later when the module is complete.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see from line 64 to line 81 of Module.js file of MinifyImage module inside src/modules/MinifyImage. There they have taken dirname/images as a file path and passed imagemin on it. @daemon1024

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niravasher that part in Minify Module seems like to be used when the inBrowser options is false. They created that to run rest and stuff prolly.

1 change: 1 addition & 0 deletions src/modules/LosslessCompression/index.js
@@ -0,0 +1 @@
module.exports = [require("./Module"), require("./info.json")];
6 changes: 6 additions & 0 deletions src/modules/LosslessCompression/info.json
@@ -0,0 +1,6 @@
{
"name": "lossless-compression",
"description": "Losslessly Compresses images",
"input": {},
"docs-link": "https://www.npmjs.com/package/compress-images"
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a reference to the docs