Search code examples
svgpng

How can I create multiple sizes of a specific image easily?


I have an image, specifically a vector image so it can be any size I need it to be. However, I need to create 8 different image files of different sizes. Here are the sizes:

  • 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

Is there any way to use a quick script (preferably on Mac or universal) that would convert a .ai, .svg or even a .png image into 8 different .png images with these file names and sizes?

Thank you!


Solution

  • You can do that in ImageMagick as follows:

    (Unix syntax)

    convert -density 300 image.svg +write mpr:img +delete \
    \( mpr:img -resize 180x180 +write AppIconMask@3x~ipad.png \) \
    \( mpr:img -resize 180x180 +write AppIconMask@3x~iphone.png \) \
    \( mpr:img -resize 152x152 +write AppIconMask@2x~ipad.png \) \
    \( mpr:img -resize 120x120 +write AppIconMask@2x~iphone.png \) \
    \( mpr:img -resize 84x84 +write GameAppIconMask@2x.png \) \
    \( mpr:img -resize 80x80 +write SpotlightAppIconMask@2x.png \) \
    \( mpr:img -resize 58x58 +write TableIconMask@2x.png \) \
    \( mpr:img -resize 40x40 +write NotificationAppIconMask@2x.png \) \
    null:
    

    (Windows syntax)

    convert -density 300 image.svg +write mpr:img +delete ^
    ( mpr:img -resize 180x180 +write AppIconMask@3x~ipad.png ) ^
    ( mpr:img -resize 180x180 +write AppIconMask@3x~iphone.png ) ^
    ( mpr:img -resize 152x152 +write AppIconMask@2x~ipad.png ) ^
    ( mpr:img -resize 120x120 +write AppIconMask@2x~iphone.png ) ^
    ( mpr:img -resize 84x84 +write GameAppIconMask@2x.png ) ^
    ( mpr:img -resize 80x80 +write SpotlightAppIconMask@2x.png ) ^
    ( mpr:img -resize 58x58 +write TableIconMask@2x.png ) ^
    ( mpr:img -resize 40x40 +write NotificationAppIconMask@2x.png ) ^
    null:
    

    I am not sure you can use @ or ~ in your filenames. Edit the names as desired and permitted by your OS.