Skip to content

Instantly share code, notes, and snippets.

@vihanb
Created April 9, 2017 02:44
Show Gist options
  • Save vihanb/0f65a38f1a8775685ca2aa49142d9864 to your computer and use it in GitHub Desktop.
Save vihanb/0f65a38f1a8775685ca2aa49142d9864 to your computer and use it in GitHub Desktop.
Automatically generates an xcode .imageset from clipboard
#!/usr/bin/env bash
folder_path="$HOME/Downloads/$1.imageset"
mkdir -p "$folder_path"
# Determine size
SIZE=${2:-30}
N_A="${SIZE}x${SIZE}"
N_B="$((SIZE*2))x$((SIZE*2))"
N_C="$((SIZE*3))x$((SIZE*3))"
pbpaste | convert -size $N_C -background transparent SVG:- \( +clone -resize $N_A -write "$folder_path/@x.png" +delete \) \( +clone -resize $N_B -write "$folder_path/@2x.png" +delete \) \( +clone -resize $N_C -write "$folder_path/@3x.png" +delete \) null:- | :
echo '{
"images" : [
{
"idiom" : "universal",
"filename" : "@x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}' > "$folder_path/Contents.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment