Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generators): Added generation ic_launcher_round.png in assets icon #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions generators/assets/imageGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,62 @@ const generateResizedAssets = (
);
};

const generateResizedRoundAssets = (
sourcePath,
destinationPath,
width,
givenHeight
) => {
const height = givenHeight || width;

const directory = path.dirname(destinationPath);
if (!fs.existsSync(directory)) {
fs.mkdirpSync(directory);
}

const psdSafeSourcePath = `${sourcePath}${
sourcePath.split('.').pop() === 'psd' ? '[0]' : ''
}`;
const maxSize = Math.max(width, height);
// percent margin
const marginPercent = 90 / 100;

// create mask
gm(maxSize, maxSize, 'none')
.drawCircle(
maxSize / 2,
maxSize / 2,
maxSize / 2,
(maxSize * (1 - marginPercent)) / 2
)
.gravity('Center')
.writeAsync(path.normalize(destinationPath + '.mask.png'))
.then(() => {
console.log(`Wrote ${destinationPath + '.mask.png'}`);
});

gm(path.normalize(psdSafeSourcePath))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Composing of images depends on creating *.mask.png. So i think this gm chain for compose original png with *.mask.png should be places inside of .writeAsync then(() => { when writeAsync is asynchronous.

.resize(maxSize * marginPercent, maxSize * marginPercent)
.gravity('Center')
.extent(maxSize, maxSize)
.write(path.normalize(destinationPath), function(err, value) {
if (!err) {
gm()
.compose('copyopacity')
.in(path.normalize(destinationPath))
.in(path.normalize(destinationPath + '.mask.png'))
.out('-composite')
.write(path.normalize(destinationPath), function(err) {
if (!err) {
console.log(`Wrote ${destinationPath}`);
// delete the mask
fs.unlink(path.normalize(destinationPath + '.mask.png'));
}
});
}
});
};

const generateIosIcons = (iconSource, iosIconFolder) =>
Promise.all(
iosIconSizes.map(size =>
Expand All @@ -148,15 +204,22 @@ const generateAndroidIcons = (
androidSrcDirectory
) =>
Promise.all(
androidIconSizes.map(size =>
androidIconSizes.map(size => {
generateResizedAssets(
iconSource,
`${assetsOutputPath}/android/app/src/${androidSrcDirectory}/res/mipmap-${
size.density
}/ic_launcher.png`,
size.value
)
)
);
generateResizedRoundAssets(
iconSource,
`${assetsOutputPath}/android/app/src/${androidSrcDirectory}/res/mipmap-${
size.density
}/ic_launcher_round.png`,
size.value
);
})
);

const generateIosSplashScreen = (splashSource, iosSplashFolder) =>
Expand Down