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

不羁岁月 提交于 2021-02-11 06:17:50

问题


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!


回答1:


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.




回答2:


You can create a Photoshop action if you are familiar with Photoshop. There might even be an action for it available for download.

A second option is to place 1 high-res version on the server, and have a script like GD or ImageMagick convert to your size. Some php might also be required.

Each of the above can achieve the results needed. It depends on if you want the work done on the server or on your personal pc/laptop.



来源:https://stackoverflow.com/questions/48073639/how-can-i-create-multiple-sizes-of-a-specific-image-easily

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!