You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过脚本快速生成指定尺寸与命名的多份应用图标图片?

Automate iOS Icon Generation from Vector/Image Files

Absolutely! You can quickly generate all 8 required icon sizes with a shell script—ImageMagick is the best cross-platform option (works seamlessly on Mac), and if you prefer no extra installs, Mac's built-in sips tool works too (with a small caveat for vector files). Here's how to do both:

Option 1: ImageMagick (Best for .ai/.svg/.png)

ImageMagick handles vector formats directly and produces crisp resized outputs, making it ideal for your vector source file.

Step 1: Install ImageMagick

On Mac, use Homebrew (if you don't have Homebrew, install it first with /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"):

brew install imagemagick

Step 2: Create the Script

Save this as generate_icons.sh:

#!/bin/bash

# Replace this with your source file path (.ai, .svg, or .png)
SOURCE_IMAGE="your_source_icon.ai"

# List of required icons: "filename.png widthxheight"
ICON_SPECS=(
    "AppIconMask@3x~ipad.png 180x180"
    "AppIconMask@3x~iphone.png 180x180"
    "AppIconMask@2x~ipad.png 152x152"
    "AppIconMask@2x~iphone.png 120x120"
    "GameAppIconMask@2x.png 84x84"
    "SpotlightAppIconMask@2x.png 80x80"
    "TableIconMask@2x.png 58x58"
    "NotificationAppIconMask@2x.png 40x40"
)

# Generate each icon
for spec in "${ICON_SPECS[@]}"; do
    FILENAME=$(echo "$spec" | awk '{print $1}')
    SIZE=$(echo "$spec" | awk '{print $2}')
    
    echo "Generating $FILENAME ($SIZE)..."
    # Resize, center-align, and ensure exact dimensions (handles non-square sources if needed)
    convert "$SOURCE_IMAGE" -resize "$SIZE" -gravity center -extent "$SIZE" "$FILENAME"
done

echo "✅ All icons generated successfully!"

Step 3: Run the Script

  1. Update SOURCE_IMAGE to point to your actual design file.
  2. Make the script executable:
    chmod +x generate_icons.sh
    
  3. Run it:
    ./generate_icons.sh
    

Option 2: Mac's Built-in sips (No Extra Installs)

Sips comes pre-installed on Mac, but it has limited support for .ai/.svg. For vector files, first export a high-resolution PNG (e.g., 1024x1024) from your design tool, then use this script:

Save as generate_icons_sips.sh:

#!/bin/bash

# Replace with your high-res source PNG path
SOURCE_IMAGE="your_high_res_icon.png"

# List of required icons: "filename.png width height"
ICON_SPECS=(
    "AppIconMask@3x~ipad.png 180 180"
    "AppIconMask@3x~iphone.png 180 180"
    "AppIconMask@2x~ipad.png 152 152"
    "AppIconMask@2x~iphone.png 120 120"
    "GameAppIconMask@2x.png 84 84"
    "SpotlightAppIconMask@2x.png 80 80"
    "TableIconMask@2x.png 58 58"
    "NotificationAppIconMask@2x.png 40 40"
)

# Generate each icon
for spec in "${ICON_SPECS[@]}"; do
    FILENAME=$(echo "$spec" | awk '{print $1}')
    WIDTH=$(echo "$spec" | awk '{print $2}')
    HEIGHT=$(echo "$spec" | awk '{print $3}')
    
    echo "Generating $FILENAME ($WIDTHx$HEIGHT)..."
    sips -z "$HEIGHT" "$WIDTH" "$SOURCE_IMAGE" --out "$FILENAME"
done

echo "✅ Done!"

Run it the same way as the ImageMagick script—update the source path, make it executable, and execute.

内容的提问来源于stack exchange,提问作者burntscarr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:06:31