diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6670f0d --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ + +# Created by https://www.gitignore.io/api/node + +### Node ### +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + + +# End of https://www.gitignore.io/api/node diff --git a/README.md b/README.md index c6fe0e5..7b81f84 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,13 @@ var webp=require('webp-converter'); //cwebp(input,output,option,result_callback) -webp.cwebp("input.jpg","output.webp","-q 80",function(status) +webp.cwebp("input.jpg","output.webp","-q 80",function(err, status) { - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); @@ -53,11 +55,13 @@ var webp=require('webp-converter'); //dwebp(input,output,option,result_callback) -webp.dwebp("input.webp","output.jpg","-o",function(status) +webp.dwebp("input.webp","output.jpg","-o",function(err, status) { - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); ``` @@ -75,11 +79,13 @@ var webp=require('webp-converter'); //gwebp(input,output,option,result_callback) -webp.gwebp("input.gif","output.webp","-q 80",function(status) +webp.gwebp("input.gif","output.webp","-q 80",function(err, status) { - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); @@ -101,11 +107,13 @@ var webp=require('webp-converter'); //webpmux_add(input,output,option_profile,set_option,result_callback) -webp.webpmux_add("input.webp","output.webp","image_profile.icc","icc",function(status){ +webp.webpmux_add("input.webp","output.webp","image_profile.icc","icc",function(err, status){ - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); @@ -126,11 +134,13 @@ var webp=require('webp-converter'); //webpmux_extract(input,output,option,result_callback) -webp.webpmux_extract("input.webp","output.icc","icc",function(status){ +webp.webpmux_extract("input.webp","output.icc","icc",function(err, status){ - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); @@ -151,11 +161,13 @@ var webp=require('webp-converter'); //webpmux_strip(input,output,option,result_callback) -webp.webpmux_strip("input.webp","ouput.webp","icc",function(status){ +webp.webpmux_strip("input.webp","ouput.webp","icc",function(err, status){ - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); @@ -168,18 +180,18 @@ webp.webpmux_strip("input.webp","ouput.webp","icc",function(status){ var webp=require('webp-converter'); -//pass input images(.webp image) path with FRAME_OPTIONS, as array,ouput image will be animated .webp image +//pass input images(.webp image) path with FRAME_OPTIONS, as array,ouput image will be animated .webp image /*FRAME_OPTIONS -file_i +di[+xi+yi[+mi[bi]]] -e.g -frame one.webp +100 -frame two.webp +100+50+50 -frame three.webp +100+50+50+1+b +e.g -frame one.webp +100 -frame two.webp +100+50+50 -frame three.webp +100+50+50+1+b -Where: file_i is the i'th frame (WebP format), xi,yi specify the image offset for this frame, -di is the pause duration before next frame, mi is the dispose method for this frame (0 for NONE or 1 for BACKGROUND) and bi is the blending method for this frame (+b for BLEND or -b for NO_BLEND). -Argument bi can be omitted and will default to +b (BLEND). Also, mi can be omitted if bi is omitted and will default to 0 (NONE). Finally, +Where: file_i is the i'th frame (WebP format), xi,yi specify the image offset for this frame, +di is the pause duration before next frame, mi is the dispose method for this frame (0 for NONE or 1 for BACKGROUND) and bi is the blending method for this frame (+b for BLEND or -b for NO_BLEND). +Argument bi can be omitted and will default to +b (BLEND). Also, mi can be omitted if bi is omitted and will default to 0 (NONE). Finally, if mi and bi are omitted then xi and yi can be omitted and will default to +0+0. -loop n @@ -188,7 +200,7 @@ e.g 10 Loop the frames n number of times. 0 indicates the frames should loop forever. Valid range is 0 to 65535 [Default: 0 (infinite)]. --bgcolor A,R,G,B +-bgcolor A,R,G,B e.g 255,255,255,255 @@ -199,11 +211,13 @@ Background color of the canvas. Where: A, R, G and B are integers in the range 0 var input=["./frames/tmp-0.webp +100","./frames/tmp-1.webp +100+50+50","./frames/tmp-2.webp +100+50+50+1+b"]; -webp.webpmux_animate(input,"anim_container.webp","10","255,255,255,255",function(status) +webp.webpmux_animate(input,"anim_container.webp","10","255,255,255,255",function(err, status) { - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); @@ -219,11 +233,13 @@ var webp=require('webp-converter'); //webpmux_getframe(input,ouput,frame number,result_callback) -webp.webpmux_getframe("anim_container.webp","output.webp","2",function(status){ +webp.webpmux_getframe("anim_container.webp","output.webp","2",function(err, status){ - //if exicuted successfully status will be '100' - //if exicuted unsuccessfully status will be '101' - console.log(status); + //if executed successfully status will be '100' + //if executed unsuccessfully status will be '101' + if (!err) { + console.log(status); + }; }); diff --git a/package.json b/package.json index 5801373..86a0cbb 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "webp-converter", - "version": "2.1.6", + "version": "2.1.7", "description": "A small node.js library for converting any image to webp file format or converting webp image to any image file format.", "main": "webpconverter.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start":"node app.js" + "start": "node app.js" }, - "repository": { + "repository": { "type": "git", "url": "https://github.com/scionoftech/webp-converter.git" }, @@ -43,5 +43,8 @@ "frames/" ], "author": "scionoftech", - "license": "MIT" + "license": "MIT", + "dependencies": { + "debug": "^2.6.0" + } } diff --git a/webpconverter.js b/webpconverter.js index 2d38646..3f49546 100644 --- a/webpconverter.js +++ b/webpconverter.js @@ -2,37 +2,39 @@ var exec = require('child_process').execFile;//get child_process module var enwebp=require('./cwebp.js');//get cwebp module(converts other image format to webp) var dewebp=require('./dwebp.js');//get dwebp module(converts webp format to other image) var gifwebp=require('./gwebp.js');//get gif2webp module(convert git image to webp) -var webpmux=require('./webpmux.js');//get webpmux module(convert non animated webp images to animated webp) +var webpmux=require('./webpmux.js');//get webpmux module(convert non animated webp images to animated webp) +var debug=require('debug')('webp-converter');//Debug module, call "DEBUG=webp-converter node yourAppHere.js" to debug /******************************************************* cwebp *****************************************************/ -//now convert image to .webp format +//now convert image to .webp format module.exports.cwebp =function(input_image,output_image,option,callback) { // input_image: input image(.jpeg, .pnp ....) -//output_image: output image .webp +//output_image: output image .webp //option: options and quality,it should be given between 0 to 100 -var query = option +' '+ input_image +' -o '+ output_image;//command to convert image +var query = option +' '+ input_image +' -o '+ output_image;//command to convert image -console.log(query); +debug(query); //enwebp() return which platform webp library should be used for conversion - exec(enwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(enwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; /******************************************************* dwebp *****************************************************/ -//now convert .webp to other image format +//now convert .webp to other image format module.exports.dwebp =function(input_image,output_image,option,callback) { @@ -40,42 +42,45 @@ module.exports.dwebp =function(input_image,output_image,option,callback) //output_image: output image(.jpeg, .pnp ....) //option: options and quality,it should be given between 0 to 100 -var query = input_image + ' ' + option + ' ' + output_image;//command to convert image - +var query = input_image + ' ' + option + ' ' + output_image;//command to convert image -console.log(query); +debug(query); //dewebp() return which platform webp library should be used for conversion - exec(dewebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { + exec(dewebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { if(error){ - callback("101"+"\n"+error);//return error code + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; /******************************************************* gif2webp *****************************************************/ -//now convert .gif image to .webp format +//now convert .gif image to .webp format module.exports.gwebp =function(input_image,output_image,option,callback) { // input_image: input image(.jpeg, .pnp ....) -//output_image: /output image .webp +//output_image: /output image .webp //option: options and quality,it should be given between 0 to 100 -var query = option +' '+ input_image +' -o '+ output_image;//command to convert image +var query = option +' '+ input_image +' -o '+ output_image;//command to convert image + +debug(query); //gifwebp() return which platform webp library should be used for conversion - exec(gifwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(gifwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; @@ -88,19 +93,22 @@ module.exports.webpmux_add =function(input_image,output_image,icc_profile,option { // input_image: input image(.webp) -//output_image: output image .webp +//output_image: output image .webp //icc_profile: icc profile //option: get or set option (icc,xmp,exif) var query = '-set '+ option +' '+ icc_profile +' '+ input_image +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; @@ -110,49 +118,55 @@ var query = '-set '+ option +' '+ icc_profile +' '+ input_image +' -o '+ output_ module.exports.webpmux_extract =function(input_image,icc_profile,option,callback) { -// input_image: input image(.webp) +// input_image: input image(.webp) //icc_profile: icc profile var query = '-get '+ option +' '+ input_image +' -o '+ icc_profile; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Strip ICC profile,XMP metadata and EXIF metadata +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Strip ICC profile,XMP metadata and EXIF metadata module.exports.webpmux_strip =function(input_image,output_image,option,callback) { -// input_image: input image(.webp) +// input_image: input image(.webp) //output_image: output image .webp var query = '-strip '+ option +' '+ input_image +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Create an animated WebP file from Webp images +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Create an animated WebP file from Webp images module.exports.webpmux_animate =function(input_images,output_image,loop,bgcolor,callback) { -// input_images: array of image(.webp) +// input_images: array of image(.webp) //output_image: animatedimage .webp //loop:Loop the frames n number of times //bgcolor: Background color of the canvas @@ -161,20 +175,23 @@ var files='-frame '+input_images[0]; var j=input_images.length; -for (i = 1; i < j; i++) { +for (i = 1; i < j; i++) { files=files+' -frame '+input_images[i]; console.log(files); } var query = files+' -loop '+ loop +' -bgcolor '+ bgcolor +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; @@ -184,19 +201,22 @@ var query = files+' -loop '+ loop +' -bgcolor '+ bgcolor +' -o '+ output_image; module.exports.webpmux_getframe =function(input_image,output_image,frame_number,callback) { -// input_image: input image(.webp) +// input_image: input image(.webp) //output_image: output image .webp //frame_number: frame number var query = '-get frame '+ frame_number +' '+ input_image +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); -}; \ No newline at end of file +}; diff --git a/webpconverter_test.js b/webpconverter_test.js index ff53858..83ead89 100644 --- a/webpconverter_test.js +++ b/webpconverter_test.js @@ -1,38 +1,40 @@ var exec = require('child_process').execFile;//get child_process module -var enwebp=require('./cwebp_test.js');//get cwebp module(converts other image format to webp) -var dewebp=require('./dwebp_test.js');//get dwebp module(converts webp format to other image) -var gifwebp=require('./gwebp_test.js');//get gif2webp module(convert git image to webp) -var webpmux=require('./webpmux_test.js');//get webpmux module(convert non animated webp images to animated webp) +var enwebp=require('./cwebp-test.js');//get cwebp module(converts other image format to webp) +var dewebp=require('./dwebp-test.js');//get dwebp module(converts webp format to other image) +var gifwebp=require('./gwebp-test.js');//get gif2webp module(convert git image to webp) +var webpmux=require('./webpmux-test.js');//get webpmux module(convert non animated webp images to animated webp) +var debug=require('debug')('webp-converter-test');//Debug module, call "DEBUG=webp-converter node yourAppHere.js" to debug /******************************************************* cwebp *****************************************************/ -//now convert image to .webp format +//now convert image to .webp format module.exports.cwebp =function(input_image,output_image,option,callback) { // input_image: input image(.jpeg, .pnp ....) -//output_image: output image .webp +//output_image: output image .webp //option: options and quality,it should be given between 0 to 100 -var query = option +' '+ input_image +' -o '+ output_image;//command to convert image +var query = option +' '+ input_image +' -o '+ output_image;//command to convert image -console.log(query); +debug(query); //enwebp() return which platform webp library should be used for conversion - exec(enwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(enwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; /******************************************************* dwebp *****************************************************/ -//now convert .webp to other image format +//now convert .webp to other image format module.exports.dwebp =function(input_image,output_image,option,callback) { @@ -40,42 +42,45 @@ module.exports.dwebp =function(input_image,output_image,option,callback) //output_image: output image(.jpeg, .pnp ....) //option: options and quality,it should be given between 0 to 100 -var query = input_image + ' ' + option + ' ' + output_image;//command to convert image - +var query = input_image + ' ' + option + ' ' + output_image;//command to convert image -console.log(query); +debug(query); //dewebp() return which platform webp library should be used for conversion - exec(dewebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { + exec(dewebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { if(error){ - callback("101"+"\n"+error);//return error code + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; /******************************************************* gif2webp *****************************************************/ -//now convert .gif image to .webp format +//now convert .gif image to .webp format module.exports.gwebp =function(input_image,output_image,option,callback) { // input_image: input image(.jpeg, .pnp ....) -//output_image: /output image .webp +//output_image: /output image .webp //option: options and quality,it should be given between 0 to 100 -var query = option +' '+ input_image +' -o '+ output_image;//command to convert image +var query = option +' '+ input_image +' -o '+ output_image;//command to convert image + +debug(query); //gifwebp() return which platform webp library should be used for conversion - exec(gifwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(gifwebp(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; @@ -88,19 +93,22 @@ module.exports.webpmux_add =function(input_image,output_image,icc_profile,option { // input_image: input image(.webp) -//output_image: output image .webp +//output_image: output image .webp //icc_profile: icc profile //option: get or set option (icc,xmp,exif) var query = '-set '+ option +' '+ icc_profile +' '+ input_image +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; @@ -110,49 +118,55 @@ var query = '-set '+ option +' '+ icc_profile +' '+ input_image +' -o '+ output_ module.exports.webpmux_extract =function(input_image,icc_profile,option,callback) { -// input_image: input image(.webp) +// input_image: input image(.webp) //icc_profile: icc profile var query = '-get '+ option +' '+ input_image +' -o '+ icc_profile; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Strip ICC profile,XMP metadata and EXIF metadata +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Strip ICC profile,XMP metadata and EXIF metadata module.exports.webpmux_strip =function(input_image,output_image,option,callback) { -// input_image: input image(.webp) +// input_image: input image(.webp) //output_image: output image .webp var query = '-strip '+ option +' '+ input_image +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Create an animated WebP file from Webp images +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Create an animated WebP file from Webp images module.exports.webpmux_animate =function(input_images,output_image,loop,bgcolor,callback) { -// input_images: array of image(.webp) +// input_images: array of image(.webp) //output_image: animatedimage .webp //loop:Loop the frames n number of times //bgcolor: Background color of the canvas @@ -161,20 +175,23 @@ var files='-frame '+input_images[0]; var j=input_images.length; -for (i = 1; i < j; i++) { +for (i = 1; i < j; i++) { files=files+' -frame '+input_images[i]; console.log(files); } var query = files+' -loop '+ loop +' -bgcolor '+ bgcolor +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); }; @@ -184,19 +201,22 @@ var query = files+' -loop '+ loop +' -bgcolor '+ bgcolor +' -o '+ output_image; module.exports.webpmux_getframe =function(input_image,output_image,frame_number,callback) { -// input_image: input image(.webp) +// input_image: input image(.webp) //output_image: output image .webp //frame_number: frame number var query = '-get frame '+ frame_number +' '+ input_image +' -o '+ output_image; +debug(query); + //webpmux() return which platform webp library should be used for conversion - exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command - { - if(error){ - callback("101"+"\n"+error);//return error code + exec(webpmux(),query.split(/\s+/), function (error, stdout, stderr) //execute command + { + if(error){ + debug(error); + callback(error, 101);//return error code }else { - callback("100\nConverted Successfully");//return success code + callback(null, 100);//return success code } }); -}; \ No newline at end of file +};