Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
image = image.resize(Jimp.AUTO,20,Jimp.RESIZE_BICUBIC)
}
image.getBase64(Jimp.AUTO, function (err, src) {
resolve(src)
})
// .toBuffer().then(data=>{
// resolve(`data:image/png;base64,${data.toString('base64')}`)
// })
}
})
}
else if(img.type.endsWith('icon') && ico.isICO(img)){
console.log(148,Date.now())
try{
ico.parse(img).then(function (images) {
console.log(149,Date.now())
const icoImage = images[0]
const imgBuffer = Buffer.from(icoImage.buffer)
console.log(151,Date.now())
Jimp.read(imgBuffer, function (err, image) {
if (err || !image) {
console.log("ERROR Failed to save file", err);
resolve(blob)
}
if(Math.max(image.bitmap.width,image.bitmap.height) <= 20){
console.log(146,Date.now())
resolve(`data:image/png;base64,${imgBuffer.toString('base64')}`)
}
else{
console.log(147,Date.now())
if(image.bitmap.width > image.bitmap.height){
async function readAsset (archive, pathname) {
if (pathname.endsWith('.ico')) {
let data = await archive.pda.readFile(pathname, 'binary')
// select the best-fitting size
let images = await ICO.parse(data, 'image/png')
let image = images[0]
for (let i = 1; i < images.length; i++) {
if (Math.abs(images[i].width - IDEAL_FAVICON_SIZE) < Math.abs(image.width - IDEAL_FAVICON_SIZE)) {
image = images[i]
}
}
let buf = Buffer.from(image.buffer)
return `data:image/png;base64,${buf.toString('base64')}`
} else {
let data = await archive.pda.readFile(pathname, 'base64')
return `data:${mime.lookup(pathname)};base64,${data}`
}
}
// if a dat, see if there's a favicon.ico or .png
try {
let data, fs
// pick the filesystem
let datResolvedUrl = url
if (url.startsWith('dat://')) {
datResolvedUrl = await dat.dns.resolveName(url)
fs = dat.library.getArchive(datResolvedUrl) // (only try if the dat is loaded)
}
if (fs) {
// try .ico
try {
data = await pda.readFile(fs, '/favicon.ico', 'binary')
if (data) {
// select the best-fitting size
let images = await ICO.parse(data, 'image/png')
let image = images[0]
for (let i = 1; i < images.length; i++) {
if (Math.abs(images[i].width - faviconSize) < Math.abs(image.width - faviconSize)) {
image = images[i]
}
}
let buf = Buffer.from(image.buffer)
sitedata.set(url, 'favicon', `data:image/png;base64,${buf.toString('base64')}`) // cache
return cb({mimeType: 'image/png', data: buf})
}
} catch (e) {
// .ico failed, ignore
data = null
}
// try .png
// From .PNG
if (isPng || isJpeg) {
resizeWriteImage(imageBuffer, imageFilepathDownloaded, notificationIconWidth, (error, imageFilepathConverted) => {
if (error) { return }
notificationOptions.icon = imageFilepathConverted
showNotification(notificationOptions, decoratedPush)
})
return
}
// From .ICO
if (isIco) {
icojs.parse(imageBuffer, 'image/png').then(imageList => {
const imageMaximum = imageList[imageList.length - 1]
resizeWriteImage(Buffer.from(imageMaximum.buffer), imageFilepathDownloaded, notificationIconWidth, (error, imageFilepathConverted) => {
if (error) { return }
notificationOptions.icon = imageFilepathConverted
showNotification(notificationOptions, decoratedPush)
})
})
}
})
// Image: Fallback to App Icon
const convertIcoToPng = async (icoData: Buffer): Promise => {
return (await icojs.parse(icoData, 'image/png'))[0].buffer;
};
const convertIcoToPng = async (icoData: Buffer): Promise => {
return (await icojs.parse(icoData, 'image/png'))[0].buffer;
};
return new Promise((resolve: (b: Buffer) => void) => {
icojs.parse(icoData, 'image/png').then((images: any) => {
resolve(images[0].buffer);
});
});
};