| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- const sharp = require("sharp");
- const fs = require("fs");
- if (!fs.existsSync("ios_icons")) {
- if (fs.mkdirSync("ios_icons")) {
- return;
- }
- }
- var iosSizes = [
- 20,
- 29,
- 40,
- 50,
- 57,
- 58,
- 60,
- 72,
- 76,
- 80,
- 87,
- 100,
- 114,
- 120,
- 144,
- 152,
- 167,
- 180,
- 1024,
- ];
- console.log("ios icons:");
- iosSizes.forEach((size) => {
- console.log(
- `<icon height="${size}" src="res/icon/ios/icon-${size}.png" width="${size}" />`
- );
- sharp("icon.png")
- .resize(size)
- .toBuffer()
- .then((data) => {
- var file = fs.open(
- `./res/icon/ios/icon-${size}.png`,
- "w",
- (err, fd) => {
- if (err) {
- return console.error(err);
- }
- fs.writeFile(fd, data, (err) => {
- if (err) {
- return console.error(err);
- }
- });
- }
- );
- })
- .catch((e) => {
- console.log(e);
- });
- });
- console.log("android icons:");
- var androidSizes = { hdpi: 72, xhdpi: 96, xxhdpi: 144, xxxhdpi: 192 };
- Object.keys(androidSizes).forEach((key) => {
- let size = androidSizes[key];
- console.log(
- `<icon src="res/icon/android/icon-${key}.png" density="${key}"/>`
- );
- const roundedCorners = Buffer.from(
- `<svg><rect x="0" y="0" width="${size}" height="${size}" rx="${
- size / 5
- }" ry="${size / 4}"/></svg>`
- );
- sharp("icon.png")
- .resize(size)
- .composite([
- {
- input: roundedCorners,
- blend: "dest-in",
- },
- ])
- .toBuffer()
- .then((data) => {
- var file = fs.open(
- `./res/icon/android/icon-${key}.png`,
- "w",
- (err, fd) => {
- if (err) {
- return console.error(err);
- }
- fs.writeFile(fd, data, (err) => {
- if (err) {
- return console.error(err);
- }
- });
- }
- );
- })
- .catch((e) => {
- console.log(e);
- });
- });
|