-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mulighet til å laste ned ikoner i PNG-format (#971)
* converterer svg til png format * gitignore update * oppdatert build steps package.json * kan nå laste ned alle ikoner i png format * zipper svg og png riktig * git fix * oppdaterte ikon svg zip * info om bruk av png ikoner * lint fix * la til png zip
- Loading branch information
Showing
15 changed files
with
154 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const fs = require("fs"); | ||
const sharp = require("sharp"); | ||
const rimraf = require("rimraf"); | ||
const zipdir = require("zip-dir"); | ||
const pLimit = require("p-limit"); | ||
|
||
const zipPng = async () => { | ||
await zipdir( | ||
"./png/", | ||
{ saveTo: "NAV-ikonpakke-png.zip" }, | ||
function (err, buffer) { | ||
if (err) { | ||
console.error(err); | ||
} | ||
} | ||
); | ||
}; | ||
|
||
const convertToPng = async () => { | ||
const inputDir = "./svg/"; | ||
const outDir = "./png/"; | ||
const sizes = [16, 24, 128, 256]; | ||
console.log("Converting icons to .png format"); | ||
|
||
const limit = pLimit(20); | ||
|
||
if (fs.existsSync(outDir)) { | ||
rimraf.sync(outDir); | ||
} | ||
fs.mkdirSync(outDir); | ||
sizes.forEach((size) => fs.mkdirSync(outDir + size.toString())); | ||
|
||
await Promise.all( | ||
fs.readdirSync(inputDir).map((file) => { | ||
return limit(() => | ||
sizes.forEach((size) => { | ||
const density = (72 * size) / 16; | ||
sharp(inputDir + file, { density }) | ||
.resize(size) | ||
.png() | ||
.toFile(outDir + size.toString() + "/" + file.replace("svg", "png")) | ||
.catch((e) => console.error(e)); | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
await zipPng(); | ||
console.log("Finished converting icons to .png format"); | ||
}; | ||
|
||
try { | ||
convertToPng(); | ||
} catch (e) { | ||
console.error(e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.