用于调整大小和重命名图像AppleScript的脚本

问题描述 投票:4回答:5

我厌倦了不断创建图像,然后必须复制,调整大小和重命名以同时支持视网膜和非视网膜iphone的情况。如果只是将图像拖到脚本中,是否可以使用脚本来自动执行此操作?

原始图像将被称为:[email protected] ...我希望脚本将其缩小50%,并在最后删除“ @ 2x”。

提前感谢

iphone applescript
5个回答
13
投票

我的工作,在Automator中-另存为应用程序

复制图像,删除@ 2x,缩小

http://new.tinygrab.com/9e397aa2b95f4d2e746e1f5a750eacece89a94dc1b.png


7
投票

这是一个applescript方式。将此代码另存为应用程序。然后,您可以1)在其上放​​置图像,或2)双击它并选择一个文件。它具有验证所删除文件名称中具有@ 2x的代码。如果是这样,它将对其进行缩放,如果没有,则什么也不会发生。我看到您已经有了解决方案,但我想向您展示applescript的应用程序“ Image Events”可以轻松缩放图像。祝你好运。

property theSeparator : "@2x"
property scaleFactor : 0.5

on run
    set f to choose file
    processTheFiles({f})
end run

on open theFiles
    processTheFiles(theFiles)
end open

on processTheFiles(theFiles)
    tell application "Image Events" to launch
    repeat with f in theFiles
        set thisFile to f as text
        if thisFile contains theSeparator then
            set savePath to text 1 thru -8 of thisFile & text -4 thru -1 of thisFile
            tell application "Image Events"
                set a to open f
                scale a by factor scaleFactor
                save a in savePath
            end tell
            delay 0.2
        end if
    end repeat
    tell application "Image Events" to quit
end processTheFiles

3
投票

请注意,所有这些方法(包括此方法)都忽略了pixel-fitting,必须手动完成。

Google调出了Bash script,它需要安装ImageMagick(通过MacPorts),但具有将图像锐化一个像素(或根据需要增加或减少)的优势。

为方便起见(此脚本从命令行获取一系列文件名):

#!/bin/sh  

IMAGES=$@  

RADIUS='1'  
SIGMA='0.0'  
FILTER=Catrom  


for image in $IMAGES  
do  
    /opt/local/bin/convert $image -sharpen ${RADIUS}x${SIGMA} -filter ${FILTER} -resize 50% `basename -s @2x.png $image`.png  
done

它是根据我链接的原始版本进行修改的,不需要修改您的$PATH


1
投票

这是does允许pixel-fitting的另一种方法,还为您节省了在所有图像上运行脚本的额外步骤;更好的结果和更好的工作流程!

先决条件是您使用Adobe Fireworks制作或导出图形。

My iOS Fireworks extension scripts add commands to the Fireworks commands menu to resize your retina graphics or your app icon to the appropriate sizes and open the export dialog for you. Installation instructions are in the README.


0
投票

对于仍在寻找脚本的人:

我写了这个python脚本,您可以在github:img-asset-creator上找到它。该脚本可以为iOS和Android创建图像资产。您唯一需要做的就是安装python3,并简化pip。我编写此脚本的原因主要是因为我想同时缩放多个图像而不必依靠互联网连接。

例如,如果您有一个像pineapple.jpg]之类的图像,并且要在所有三个尺寸的iOS中使用它,而最大的一个尺寸是width << 1200px] >您可以运行以下命令:python3 imgasset.py -iOS -w 1200 pineapple.jpg

该脚本当前不支持按比例缩小,但是我会尽快添加。 
© www.soinside.com 2019 - 2024. All rights reserved.