Skip to content

Commit

Permalink
Modify weirdly sized SVGs to fit in a 24x24 viewBox
Browse files Browse the repository at this point in the history
  • Loading branch information
the-question committed Aug 1, 2018
1 parent 881f692 commit 2fc0836
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/material-ui-icons/scripts/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@ function downloadIcon(icon) {
throw new Error(`status ${response.status}`);
}
const SVG = await response.text();
if (icon.imageUrls && icon.imageUrls[theme]) {
if (size < 24) {
const translate = Math.floor((24 - size) / 2);
if (translate > 0) {
SVG.replace(/<path /g, `<path transform="translate(${translate}, ${translate})" `);
}
}
if (size > 24) {
const scale = Math.round((24 / size) * 100) / 100; // Keep a maximum of 2 decimals
if (scale < 1) {
SVG.replace(/<path /g, `<path transform="scale(${scale}, ${scale})" `);
}
}
}
await fse.writeFile(
path.join(
__dirname,
`../material-io-tools-icons/ic_${icon.id}${themeMap[theme]}_${size}px.svg`,
),
path.join(__dirname, `../material-io-tools-icons/ic_${icon.id}${themeMap[theme]}_24px.svg`),
SVG,
);
}),
Expand Down

0 comments on commit 2fc0836

Please sign in to comment.