image-convert
Advanced tools
Comparing version 0.1.312 to 0.1.313
25
index.js
@@ -12,12 +12,18 @@ // Copyright 2016 Arshpreet Wadehra | ||
; | ||
function dataURLtoFile(dataurl, output_format) { | ||
var bstr = atob(dataurl), n = bstr.length, u8arr = new Uint8Array(n); | ||
while(n--){ | ||
u8arr[n] = bstr.charCodeAt(n); | ||
} | ||
let file_name = new Date().getTime() + "."+output_format; | ||
function GetFilename(url) { | ||
if (url) | ||
{ | ||
var m = url.toString().match(/.*\/(.+?)\./); | ||
if (m && m.length > 1) | ||
{ | ||
return m[1]; | ||
} | ||
} | ||
return ""; | ||
} | ||
function dataURLtoFile(dataurl, filename,output_format) { | ||
var file = new File({ | ||
name: file_name, // required | ||
name: filename+"."+output_format, // required | ||
type: "image/"+output_format, // optional | ||
buffer: [u8arr]; | ||
buffer: new Buffer(dataurl,'base64') | ||
}); | ||
@@ -35,2 +41,3 @@ return file; | ||
output_format = "jpg" | ||
let filename = GetFilename(url); | ||
try{ | ||
@@ -44,3 +51,3 @@ request.get(url, function (err, res, body) { | ||
buffer = image(body).size(size).encode(output_format,{quality:quality}); | ||
callback(null,buffer,dataURLtoFile(buffer,output_format)); | ||
callback(null,buffer,dataURLtoFile(buffer,filename,output_format)); | ||
}); | ||
@@ -47,0 +54,0 @@ } |
{ | ||
"name": "image-convert", | ||
"version": "0.1.312", | ||
"version": "0.1.313", | ||
"description": "convert image to different format like gif2jpg jpg2png also manage the quality & size", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,3 +16,3 @@ # image-convert | ||
output_format:<output_format>, | ||
size: <size{integer}>},function(err,res){ | ||
size: <size{integer}>},function(err,buffer,file){//buffer=> base64 encode, file=> file object | ||
if(!err) | ||
@@ -33,5 +33,8 @@ console.log(res);//img buffer | ||
size: 300//defualt original | ||
},function(err,res){ | ||
},function(err,buffer,file){ | ||
if(!err) | ||
{ | ||
console.log(res);//img buffer | ||
console.log(file); | ||
} | ||
}) | ||
@@ -38,0 +41,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4351
56
45