使用电容器为离子框架生成应用程序图标和启动屏幕图像

A handy script to help you generate app icon and splash screen images for your Ionic app using Capacitor.

一个方便的脚本,可帮助您使用Capacitor为Ionic应用程序生成应用程序图标和启动屏幕图像。

Ionic Framework is awesome for build hybrid mobile apps and progressive web apps (PWA). And Capacitor is a great alternative to using Cordova taking a more modern approach to leveraging native SDKs that works on both mobile and web.

Ionic Framework非常适合构建混合移动应用程序和渐进式Web应用程序(PWA)。 与使用Cordova采取更现代的方法来利用可在移动和Web上运行的本地SDK相比, Capacitor是一个很好的选择。

However after making to switch to Capacitor, I missed using cordova-resources which generates all the various sizes of the app icon and splash screen simply by running ionic cordova resources.

但是,在切换到电容器后 ,我错过了使用cordova-resources的功能 ,该资源仅通过运行ionic cordova resources即可生成所有大小的应用程序图标和启动屏幕。

Generate perfectly sized icons and splash screens from PNG source images for your Cordova platforms with this command.

使用此命令从适用于Cordova平台的PNG源图像生成大小合适的图标和启动屏幕。

The source image for icons should ideally be at least 1024×1024px and located at resources/icon.png. The source image for splash screens should ideally be at least 2732×2732px and located at resources/splash.png.

理想情况下,图标的源图像应至少为1024×1024px,并位于resources / icon.png 。 初始屏幕的源图像理想上应至少为2732×2732px并位于resources / splash.png

Since other Ionic developers using Capacitor are probably also missing this functionality, I wrote a script to add this to your projects.

由于使用电容器的其他Ionic开发人员可能也缺少此功能 ,因此我编写了一个脚本将其添加到您的项目中

https://gist.github.com/dalezak/a6b1de39091f4ace220695d72717ac71

https://gist.github.com/dalezak/a6b1de39091f4ace220695d72717ac71

In your Ionic Capacitor project, just follow these steps:

在您的离子电容器项目中,只需执行以下步骤:

  1. Run npm install cordova-res --save-dev

    运行npm install cordova-res --save-dev

  2. Create 1024x1024px icon at resources/icon.png

    resources/icon.png创建1024x1024px图标

  3. Create 2732x2732px splash at resources/splash.png

    resources/splash.png创建2732x2732px飞溅

  4. Add "resources": "cordova-res ios && cordova-res android && node scripts/resources.js" to scripts in package.json

    package.json scripts中添加"resources": "cordova-res ios && cordova-res android && node scripts/resources.js" package.json

  5. Copy to script below to scripts/resources.js

    复制到脚本下面scripts/resources.js

  6. Run sudo chmod -R 777 scripts/resources.js

    运行sudo chmod -R 777 scripts/resources.js

  7. Run npm run resources

    运行npm run resources

That’s it! Now you can easily generate your app icon and splash screen for your Capacitor projects. 🤗

而已! 现在,您可以轻松地为电容器项目生成应用程序图标和启动屏幕。 🤗

const fs = require('fs');
const SOURCE_IOS_ICON = 'resources/ios/icon/';
const SOURCE_IOS_SPLASH = 'resources/ios/splash/';
const TARGET_IOS_ICON = 'ios/App/App/Assets.xcassets/AppIcon.appiconset/';
const TARGET_IOS_SPLASH = 'ios/App/App/Assets.xcassets/Splash.imageset/';
const SOURCE_ANDROID_ICON = 'resources/android/icon/';
const SOURCE_ANDROID_SPLASH = 'resources/android/splash/';
const TARGET_ANDROID_ICON = 'android/app/src/main/res/';
const TARGET_ANDROID_SPLASH = 'android/app/src/main/res/';
const IOS_ICONS = [
{ source: 'icon-20.png', target: 'AppIcon-20x20@1x.png' },
{ source: 'icon-20@2x.png', target: 'AppIcon-20x20@2x.png' },
{ source: 'icon-20@2x.png', target: 'AppIcon-20x20@2x-1.png' },
{ source: 'icon-20@3x.png', target: 'AppIcon-20x20@3x.png' },
{ source: 'icon-29.png', target: 'AppIcon-29x29@1x.png' },
{ source: 'icon-29@2x.png', target: 'AppIcon-29x29@2x.png' },
{ source: 'icon-29@2x.png', target: 'AppIcon-29x29@2x-1.png' },
{ source: 'icon-29@3x.png', target: 'AppIcon-29x29@3x.png' },
{ source: 'icon-40.png', target: 'AppIcon-40x40@1x.png' },
{ source: 'icon-40@2x.png', target: 'AppIcon-40x40@2x.png' },
{ source: 'icon-40@2x.png', target: 'AppIcon-40x40@2x-1.png' },
{ source: 'icon-40@3x.png', target: 'AppIcon-40x40@3x.png' },
{ source: 'icon-60@2x.png', target: 'AppIcon-60x60@2x.png' },
{ source: 'icon-60@3x.png', target: 'AppIcon-60x60@3x.png' },
{ source: 'icon-76.png', target: 'AppIcon-76x76@1x.png' },
{ source: 'icon-76@2x.png', target: 'AppIcon-76x76@2x.png' },
{ source: 'icon-83.5@2x.png', target: 'AppIcon-83.5x83.5@2x.png' },
{ source: 'icon-1024.png', target: 'AppIcon-512@2x.png' }
];
const IOS_SPLASHES = [
{ source: 'Default-Portrait@~ipadpro.png', target: 'splash-2732x2732.png' },
{ source: 'Default-Portrait@~ipadpro.png', target: 'splash-2732x2732-1.png' },
{ source: 'Default-Portrait@~ipadpro.png', target: 'splash-2732x2732-2.png' }
];
const ANDROID_ICONS = [
{ source: 'drawable-ldpi-icon.png', target: 'drawable-hdpi-icon.png' },
{ source: 'drawable-mdpi-icon.png', target: 'mipmap-mdpi/ic_launcher.png' },
{ source: 'drawable-mdpi-icon.png', target: 'mipmap-mdpi/ic_launcher_round.png' },
{ source: 'drawable-mdpi-icon.png', target: 'mipmap-mdpi/ic_launcher_foreground.png' },
{ source: 'drawable-hdpi-icon.png', target: 'mipmap-hdpi/ic_launcher.png' },
{ source: 'drawable-hdpi-icon.png', target: 'mipmap-hdpi/ic_launcher_round.png' },
{ source: 'drawable-hdpi-icon.png', target: 'mipmap-hdpi/ic_launcher_foreground.png' },
{ source: 'drawable-xhdpi-icon.png', target: 'mipmap-xhdpi/ic_launcher.png' },
{ source: 'drawable-xhdpi-icon.png', target: 'mipmap-xhdpi/ic_launcher_round.png' },
{ source: 'drawable-xhdpi-icon.png', target: 'mipmap-xhdpi/ic_launcher_foreground.png' },
{ source: 'drawable-xxhdpi-icon.png', target: 'mipmap-xxhdpi/ic_launcher.png' },
{ source: 'drawable-xxhdpi-icon.png', target: 'mipmap-xxhdpi/ic_launcher_round.png' },
{ source: 'drawable-xxhdpi-icon.png', target: 'mipmap-xxhdpi/ic_launcher_foreground.png' },
{ source: 'drawable-xxxhdpi-icon.png', target: 'mipmap-xxxhdpi/ic_launcher.png' },
{ source: 'drawable-xxxhdpi-icon.png', target: 'mipmap-xxxhdpi/ic_launcher_round.png' },
{ source: 'drawable-xxxhdpi-icon.png', target: 'mipmap-xxxhdpi/ic_launcher_foreground.png' }
];
const ANDROID_SPLASHES = [
{ source: 'drawable-land-mdpi-screen.png', target: 'drawable/splash.png' },
{ source: 'drawable-land-mdpi-screen.png', target: 'drawable-land-mdpi/splash.png' },
{ source: 'drawable-land-hdpi-screen.png', target: 'drawable-land-hdpi/splash.png' },
{ source: 'drawable-land-xhdpi-screen.png', target: 'drawable-land-xhdpi/splash.png' },
{ source: 'drawable-land-xxhdpi-screen.png', target: 'drawable-land-xxhdpi/splash.png' },
{ source: 'drawable-land-xxxhdpi-screen.png', target: 'drawable-land-xxxhdpi/splash.png' },
{ source: 'drawable-port-mdpi-screen.png', target: 'drawable-port-mdpi/splash.png' },
{ source: 'drawable-port-hdpi-screen.png', target: 'drawable-port-hdpi/splash.png' },
{ source: 'drawable-port-xhdpi-screen.png', target: 'drawable-port-xhdpi/splash.png' },
{ source: 'drawable-port-xxhdpi-screen.png', target: 'drawable-port-xxhdpi/splash.png' },
{ source: 'drawable-port-xxxhdpi-screen.png', target: 'drawable-port-xxxhdpi/splash.png' }
];
function copyImages(sourcePath, targetPath, images) {
for (const icon of images) {
let source = sourcePath + icon.source;
let target = targetPath + icon.target;
fs.copyFile(source, target, err => {
if (err) throw err;
console.log(`${source} >> ${target}`);
});
}
}
copyImages(SOURCE_IOS_ICON, TARGET_IOS_ICON, IOS_ICONS);
copyImages(SOURCE_IOS_SPLASH, TARGET_IOS_SPLASH, IOS_SPLASHES);
copyImages(SOURCE_ANDROID_ICON, TARGET_ANDROID_ICON, ANDROID_ICONS);
copyImages(SOURCE_ANDROID_SPLASH, TARGET_ANDROID_SPLASH, ANDROID_SPLASHES);

翻译自: https://medium.com/@dalezak/generate-app-icon-and-splash-screen-images-for-ionic-framework-using-capacitor-e1f8c6ef0fd4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值