Skip to content

Commit

Permalink
with the lights out, it's less dangerous
Browse files Browse the repository at this point in the history
  • Loading branch information
busterc committed Jul 18, 2014
0 parents commit c10a255
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 0 deletions.
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# cordova-resource-generators
<!--Cordova generators for app icons and splash screens (can be used as hooks, or not)-->
Quickly generate mobile app icons and splash screens for Cordova builds and have them automatically copied to the appropriate `/platforms/*` directories.

* You must have [ImageMagick](http://www.imagemagick.org/) installed
* Doesn't use or provide hooks, because I personally don't need to generate on every build (make hooks if you need them)
* Creates a `/resources/` directory as a sibling to `/www/` rather than beneath it
* Also copies icons and splash screens from `/resources/` to the appropriate `/platforms/*` directories (or will create the directory, if the commands are not run from the root of your app)
* Currently only generates iOS and Android resources
* Currently only tested on OS X
* Made for Cordova 3.4 and newer
* Use aliases, if that's your thang

## Version
0.1.0

## Installation on OS X
```sh
$ curl https://raw.githubusercontent.com/busterc/cordova-resource-generators/master/install.sh | sh
```
_By all means, examine the [install.sh](install.sh) file before installing._

## Usage
### Generate Icons
```sh
$ cd path/to/your/app
$ cordova-generate-icons path/to/your/img.png
```

### Generate Splash Screens
```sh
$ cd path/to/your/app
$ cordova-generate-splash-screens path/to/your/img.png
```
<!--
## Easter Egg Aliases
_you know, for your .bash_profile or .bashrc or .profile_
```sh
alias cgicons="cordova-generate-icons"
alias cgscreens="cordova-generate-splash-screens"
```
-->

## Dependencies
* [ImageMagick](http://www.imagemagick.org/) - Convert, Edit, And Compose Images

## License
The MIT License (MIT)

Copyright (c) 2014 Buster Collings

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
64 changes: 64 additions & 0 deletions cordova-generate-icons
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
# Generate Cordova icons

function usage() {
echo "usage: $0 <image-filename> [output-directory]";
exit 1;
}

[ "$1" ] || usage
[ "$2" ] || set "$1" "."

image=$1
output=$2/resources/icon

devices=ios,android #,windows-phone,bada,bada-wac,blackberry,webos
eval mkdir -p "$output/{$devices}"

# Show the user some progress by outputing all commands being run.
set -x

# Explicitly set background in case image is transparent (see: #3)
convert="convert $image -background none"

function androidConvertIcon() {
drawables=drawable,drawable-ldpi,drawable-mdpi,drawable-hdpi,drawable-xhdpi
eval mkdir -p "$output/android/{$drawables}"

$convert -resize 36x36 "$output/android/drawable-ldpi/icon.png"
$convert -resize 48x48 "$output/android/drawable-mdpi/icon.png"
$convert -resize 72x72 "$output/android/drawable-hdpi/icon.png"
$convert -resize 96x96 "$output/android/drawable-xhdpi/icon.png"
$convert -resize 96x96 "$output/android/drawable/icon.png"

function androidCopyIcon() {
androidOutput=$(find . -type d | grep "platforms/android/res$")
find . -type d | grep "resources/icon/android/drawable" | xargs -I{} cp -R {} $androidOutput
}
androidCopyIcon
}
androidConvertIcon

function iosConvertIcon() {
$convert -resize 29x29 "$output/ios/Icon-Small.png"
$convert -resize 40x40 "$output/ios/Icon-Small-40.png"
$convert -resize 50x50 "$output/ios/Icon-Small-50.png"
$convert -resize 57x57 "$output/ios/Icon.png"
$convert -resize 58x58 "$output/ios/Icon-Small@2x.png"
$convert -resize 72x72 "$output/ios/Icon-72.png"
$convert -resize 76x76 "$output/ios/Icon-76.png"
$convert -resize 80x80 "$output/ios/Icon-Small-40@2x.png"
$convert -resize 100x100 "$output/ios/Icon-Small-50@2x.png"
$convert -resize 114x114 "$output/ios/Icon@2x.png"
$convert -resize 120x120 "$output/ios/Icon-60@2x.png"
$convert -resize 144x144 "$output/ios/Icon-72@2x.png"
$convert -resize 152x152 "$output/ios/Icon-76@2x.png"
$convert -resize 512x512 "$output/ios/iTunesArtwork.png"
$convert -resize 1024x1024 "$output/ios/iTunesArtwork@2x.png"

function iosCopyIcon() {
cp $(find . | grep "resources/icon/ios/.*\.png") $(find . -type d | grep "platforms/ios/.*Resources/icons")
}
iosCopyIcon
}
iosConvertIcon
60 changes: 60 additions & 0 deletions cordova-generate-splash-screens
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
# Generate Cordova splash screens

function usage() {
echo "usage: $0 <image-filename> <background-color> [output-directory]";
exit 1;
}

[ "$1" ] && [ "$2" ] || usage
[ "$3" ] || set "$1" "$2" "."

image=$1
bgcolor=$2
output=$3/resources/splash

devices=ios,android #,windows-phone,bada,bada-wac,blackberry,webos
eval mkdir -p "$output/{$devices}"

# Show the user some progress by outputing all commands being run.
set -x

convert="convert $1 -background $bgcolor -gravity center"

function androidConvertSplash() {
drawables=drawable-land-ldpi,drawable-land-mdpi,drawable-land-hdpi,drawable-land-xhdpi,drawable-port-ldpi,drawable-port-mdpi,drawable-port-hdpi,drawable-port-xhdpi
eval mkdir -p "$output/android/{$drawables}"

$convert -resize 512x512 -extent 720x1280 "$output/android/drawable-port-xhdpi/screen.png"
$convert -resize 256x256 -extent 480x800 "$output/android/drawable-port-hdpi/screen.png"
$convert -resize 256x256 -extent 320x480 "$output/android/drawable-port-mdpi/screen.png"
$convert -resize 128x128 -extent 200x320 "$output/android/drawable-port-ldpi/screen.png"

$convert -resize 512x512 -extent 1280x720 "$output/android/drawable-land-xhdpi/screen.png"
$convert -resize 256x256 -extent 800x480 "$output/android/drawable-land-hdpi/screen.png"
$convert -resize 256x256 -extent 480x320 "$output/android/drawable-land-mdpi/screen.png"
$convert -resize 128x128 -extent 320x200 "$output/android/drawable-land-ldpi/screen.png"

function androidCopySplash() {
androidOutput=$(find . -type d | grep "platforms/android/res$")
find . -type d | grep "resources/splash/android/drawable" | xargs -I{} cp -R {} $androidOutput
}
androidCopySplash
}
androidConvertSplash

function iosConvertSplash() {
$convert -resize 512x512 -extent 640x1136 "$output/ios/Default-568h@2x~iphone.png"
$convert -resize 1024x1024 -extent 2048x1496 "$output/ios/Default-Landscape@2x~ipad.png"
$convert -resize 512x512 -extent 1024x748 "$output/ios/Default-Landscape~ipad.png"
$convert -resize 1024x1024 -extent 1536x2008 "$output/ios/Default-Portrait@2x~ipad.png"
$convert -resize 512x512 -extent 768x1004 "$output/ios/Default-Portrait~ipad.png"
$convert -resize 256x256 -extent 320x480 "$output/ios/Default~iphone.png"
$convert -resize 256x256 -extent 640x960 "$output/ios/Default@2x~iphone.png"

function iosCopySplash() {
cp $(find . | grep "resources/splash/ios/.*\.png") $(find . -type d | grep "platforms/ios/.*/Resources/splash")
}
iosCopySplash
}
iosConvertSplash
59 changes: 59 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh

# This is the cordova-resource-generators install script!
# Are you looking at this in your web browser, and would like to install?
# Just open up your terminal and type:
#
# curl https://raw.githubusercontent.com/busterc/cordova-resource-generators/master/install.sh | sh
#
# Currently supports Mac OS X

set -e
set -u

# Display everything on stderr.
exec 1>&2

UNAME=$(uname)
if [ "$UNAME" != "Darwin" ] ; then
echo "Sorry, this OS is not supported yet."
exit 1
fi

INSTALL_URL="https://github.com/busterc/cordova-resource-generators/"
PREFIX="/usr/local"
INSTALL_BIN="$PREFIX/bin"

# New macs (10.9+) don't ship with /usr/local, however it is still in
# the default PATH. We still install there, we just need to create the
# directory first.
if [ ! -d "$INSTALL_BIN" ] ; then
sudo mkdir -m 755 "$PREFIX" || true
sudo mkdir -m 755 "$INSTALL_BIN" || true
fi

GEN_ICONS="/cordova-generate-icons"
GEN_SPLASHES="/cordova-generate-splash-screens"

curl -# -o $INSTALL_BIN$GEN_ICONS $INSTALL_URL$GEN_ICONS
sudo chmod +x $INSTALL_BIN$GEN_ICONS

curl -# -o $INSTALL_BIN$GEN_SPLASHES $INSTALL_URL$GEN_SPLASHES
sudo chmod +x $INSTALL_BIN$GEN_SPLASHES

cat <<"EOF"
# Installation Complete
To generate icons:
$ cd path/to/your/app
$ cordova-generate-icons path/to/icon.png
To generate splash screens:
$ cd path/to/your/app
$ cordova-generate-splash-screens path/to/icon.png
EOF

0 comments on commit c10a255

Please sign in to comment.