简体   繁体   English

将 svg 转换为 iOS 和 Android 的应用程序图标的最佳方法是什么

[英]What is the best way of converting a svg into App Icons for both iOS and Android

I'm looking for a tool that can generate the different sizes of icons for the iOS and Android apps from a svg image.我正在寻找一种工具,可以从svg图像为 iOS 和 Android 应用程序生成不同大小的图标。

Google hasn't been really able to provide me with any "one-click" solution.谷歌并没有真正能够为我提供任何“一键式”解决方案。 Are there any tools out there which are less well known?是否有一些鲜为人知的工具? or perhaps some simple batch scripts that achieve the same?或者一些简单的批处理脚本可以实现相同的目的?

Ideally something I could run on my windows 10 machine, but linux would work too.理想情况下,我可以在我的 windows 10 机器上运行,但 linux 也可以。

首先从这个链接https://svgtopng.com/将你的 SVG 转换为 PNG 一旦你转换 .PNG 然后使用这个链接https://makeappicon.com/为 android 和 iOS 创建应用程序图标。

My choice is https://github.com/sterlp/svg2png .我的选择是https://github.com/sterlp/svg2png For IOS:对于 IOS:

java -jar svg2png.jar -f app_icon.svg -o yourFolder/Assets.xcassets/AppIcon.appiconset -c ios_icon.json

With ios_icon.json like that:使用 ios_icon.json 像这样:

{
  "files": [
    {
      "nameSuffix": "-20x20@1x",
      "height": 20,
      "width": 20
    },
    {
      "nameSuffix": "-20x20@2x",
      "height": 40,
      "width": 40
    },
    {
      "nameSuffix": "-20x20@3x",
      "height": 60,
      "width": 60
    },
    {
      "nameSuffix": "-29x29@1x",
      "height": 29,
      "width": 29
    },
    {
      "nameSuffix": "-29x29@2x",
      "height": 58,
      "width": 58
    },
    {
      "nameSuffix": "-29x29@3x",
      "height": 87,
      "width": 87
    },
    {
      "nameSuffix": "-40x40@1x",
      "height": 40,
      "width": 40
    },
    {
      "nameSuffix": "-40x40@2x",
      "height": 80,
      "width": 80
    },
    {
      "nameSuffix": "-40x40@3x",
      "height": 120,
      "width": 120
    },
    {
      "nameSuffix": "-60x60@2x",
      "height": 120,
      "width": 120
    },
    {
      "nameSuffix": "-60x60@3x",
      "height": 180,
      "width": 180
    },
    {
      "nameSuffix": "-76x76@1x",
      "height": 76,
      "width": 76
    },
    {
      "nameSuffix": "-76x76@2x",
      "height": 152,
      "width": 152
    },
    {
      "nameSuffix": "-83.5x83.5@2x",
      "height": 167,
      "width": 167
    },
    {
      "nameSuffix": "-1024x1024@1x",
      "height": 1024,
      "width": 1024
    }
  ]
}

Just make sure generated png files match your configuration from AppIcon.appiconset/Contents.json.只需确保生成的 png 文件与 AppIcon.appiconset/Contents.json 中的配置匹配即可。 Mine is我的是

{
  "images" : [
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "size" : "20x20",
      "filename" : "app_icon-20x20@2x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "3x",
      "size" : "20x20",
      "filename" : "app_icon-20x20@3x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "size" : "29x29",
      "filename" : "app_icon-29x29@2x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "3x",
      "size" : "29x29",
      "filename" : "app_icon-29x29@3x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "size" : "40x40",
      "filename" : "app_icon-40x40@2x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "3x",
      "size" : "40x40",
      "filename" : "app_icon-40x40@3x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "size" : "60x60",
      "filename" : "app_icon-60x60@2x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "3x",
      "size" : "60x60",
      "filename" : "app_icon-60x60@3x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "size" : "20x20",
      "filename" : "app_icon-20x20@1x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "size" : "20x20",
      "filename" : "app_icon-20x20@2x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "size" : "29x29",
      "filename" : "app_icon-29x29@1x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "size" : "29x29",
      "filename" : "app_icon-29x29@2x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "size" : "40x40",
      "filename" : "app_icon-40x40@1x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "size" : "40x40",
      "filename" : "app_icon-40x40@2x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "size" : "76x76",
      "filename" : "app_icon-76x76@1x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "size" : "76x76",
      "filename" : "app_icon-76x76@2x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "size" : "83.5x83.5",
      "filename" : "app_icon-83.5x83.5@2x.png"
    },
    {
      "idiom" : "ios-marketing",
      "scale" : "1x",
      "size" : "1024x1024",
      "filename" : "app_icon-1024x1024@1x.png"
    }
  ],
  "info" : {
    "author" : "xcode",
    "version" : 1
  }
}

For Android please refer to README on https://github.com/sterlp/svg2png or create your own json config.对于 Android,请参阅https://github.com/sterlp/svg2png上的 README 或创建您自己的 json 配置。

This is quite late already and this is for ANDROID, but you can actually convert an svg file directly in android studio, right click on drawable folder from res folder and select vector asset:这已经很晚了,这是针对 ANDROID 的,但您实际上可以直接在 android studio 中转换 svg 文件,右键单击 res 文件夹中的 drawable 文件夹并选择矢量资产:

打开矢量资产

Then select local file (SVG, PSD)然后选择本地文件(SVG、PSD)

本地文件 SVG 或 PSD

You can then select the svg file from the path field and android studio will directly convert the file as a resource.然后您可以从路径字段中选择 svg 文件,android studio 将直接将该文件转换为资源。

Modern Design tools(Figma, Zeplin...) allows you generate necessary images for iOS, Android现代设计工具(Figma、Zeplin...)允许您为 iOS、Android 生成必要的图像

The easiest way I've found is just using this website: https://appicon.co/我发现的最简单的方法就是使用这个网站: https://appicon.co/

You can simply drag and drop your SVG file and export to any devices you need.您可以简单地拖放 SVG 文件并导出到您需要的任何设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM