gpt4 book ai didi

ios - 将图像集@ 2x和@ 3x大小从Sketch导出到Xcode

转载 作者:行者123 更新时间:2023-12-01 16:30:22 24 4
gpt4 key购买 nike

使用以下代码导出图像,但是正如我将文件大小指定为40 80 120一样,对于它创建的每个具有相同大小的图像。应考虑默认图像大小,并应创建@ 2x和@ 3x图像。

function exportIcons()
{

sketchtool export slices "$SKETCH_FILE" \
--output="$ICONS_DIR" \
--formats="png" \
# create assets to XCode
cd $ICONS_DIR

for file in *.png
do

filename=${file%%@*}



fname=${filename:0:${filename}-4}

# create imageset file
assets_name="$fname".imageset
icon_assets_dir="$IMAGES_ASSETS_DIR"/"$assets_name"


png="$fname"".png"
twopng="$fname""@2x.png"
threepng="$fname""@3x.png"

height=${sips -g pixelHeight "$file"}

printf "height >> $height \n"

cp -p "$filename" "$png"
sips -Z 40 "$png"

cp -p "$filename" "$twopng"
sips -Z 80 "$twopng"

cp -p "$filename" "$threepng"
sips -Z 120 "$threepng"

cat << EOF > Contents.json
{
"images" : [
{
"idiom" : "iphone",
"filename" : "$png",
"scale" : "1x"
},{
"idiom" : "iphone",
"filename" : "$twopng",
"scale" : "2x"
},
{
"idiom" : "iphone",
"filename" : "$threepng",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
EOF


# copy imageset file to XCode
mkdir -p "$icon_assets_dir"

/bin/cp "$png" "$icon_assets_dir"/"$png"
/bin/cp "$twopng" "$icon_assets_dir"/"$twopng"
/bin/cp "$threepng" "$icon_assets_dir"/"$threepng"

/bin/cp Contents.json "$icon_assets_dir"/Contents.json
done

cd $PROJECT_DIR

# remove unused files
rm -rf "$ICONS_DIR"
}

最佳答案

这是我发现根据默认图像生成@ 2x和@ 3x的解决方案:

# grab the identify string, make sure it succeeded
IMG_CHARS=$(identify "${file}" 2> /dev/null) || die "${file} is not a proper image"

# grab width and height
IMG_CHARS=$(echo "${IMG_CHARS}" | sed -n 's/\(^.*\)\ \([0-9]*\)x\([0-9]*\)\ \(.*$\)/\2 \3/p')

width=$(echo "${IMG_CHARS}" | awk '{print $1}')
height=$(echo "${IMG_CHARS}" | awk '{print $2}')

cp -p "$filename" "$png"
sips -Z "$(($width * 1))" "$(($height * 1))" "$png"

cp -p "$filename" "$twopng"
sips -Z "$(($width * 2))" "$(($height * 2))" "$twopng"

cp -p "$filename" "$threepng"
sips -Z "$(($width * 3))" "$(($height * 3))" "$threepng"

关于ios - 将图像集@ 2x和@ 3x大小从Sketch导出到Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31983085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com