-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-icon.mjs
More file actions
74 lines (61 loc) · 2.51 KB
/
fix-icon.mjs
File metadata and controls
74 lines (61 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
/**
* Fix Windows taskbar icon by removing the blue background
*/
import sharp from 'sharp';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function main() {
const workspaceRoot = 'c:\\Users\\seans\\Documents\\GitHub\\TimeLens';
const sourceIcon = path.join(workspaceRoot, 'src-tauri', 'icons', 'icon.png');
const outputDir = path.join(workspaceRoot, 'src-tauri', 'windows', 'msix-staging', 'Assets');
const outputIcon = path.join(outputDir, 'Square44x44Logo.png');
console.log('Fixing Windows taskbar icon...');
console.log(`Source: ${sourceIcon}`);
console.log(`Output: ${outputIcon}`);
try {
// Read the source image
const image = sharp(sourceIcon);
const metadata = await image.metadata();
console.log(`Image size: ${metadata.width}x${metadata.height}`);
// Get raw pixel data
const { data } = await image.raw().toBuffer({ resolveWithObject: true });
// Process pixels - remove blue background
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
// If this pixel is part of the blue background, make it transparent
if (b > r + 20 && b > g + 20 && (r + g + b) < 300) {
data[i + 3] = 0; // Set alpha to 0 (transparent)
} else {
data[i + 3] = 255; // Set alpha to 255 (opaque)
}
}
// Create a new image from the processed pixel data and resize
await sharp(data, {
raw: {
width: metadata.width,
height: metadata.height,
channels: 4
}
})
.resize(44, 44, {
fit: 'inside',
background: { r: 0, g: 0, b: 0, alpha: 0 }
})
.png()
.toFile(outputIcon);
console.log(`\n✓ Successfully created taskbar icon: ${outputIcon}`);
console.log('✓ Blue background has been removed');
console.log('✓ Icon now has a transparent background');
console.log('\nThe taskbar icon will now display correctly in Windows without the blue background.');
} catch (error) {
console.error(`✗ Error: ${error.message}`);
process.exit(1);
}
}
main();