Skip to content

Instantly share code, notes, and snippets.

@peterp
Created July 23, 2017 07:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterp/1051825fa84f20cb943e303f09f6775c to your computer and use it in GitHub Desktop.
Save peterp/1051825fa84f20cb943e303f09f6775c to your computer and use it in GitHub Desktop.
React Native: Convert SVG images to PNG images
#!/bin/sh
rsvg-convert -v > /dev/null 2>&1 || { echo "rsvg-convert is not installed, use: brew install librsvg." >&2; exit 1; }
ASSETS_FOLDER=$1
if [ "$ASSETS_FOLDER" == "" ]; then
echo "Usage: $0 /path/to/svg/assets/" >&2
exit 1
fi
if [ ! -d "$ASSETS_FOLDER" ]; then
echo "$ASSETS_FOLDER path not found" >&2
exit 1
fi
for FILE_PATH in $(find $ASSETS_FOLDER -name '*.svg'); do
PATH_NO_EXT="${FILE_PATH%.*}"
echo $FILE_PATH
rsvg-convert $FILE_PATH -o "${PATH_NO_EXT}.png"
rsvg-convert $FILE_PATH -x 2 -y 2 -o "${PATH_NO_EXT}@2x.png"
rsvg-convert $FILE_PATH -x 3 -y 3 -o "${PATH_NO_EXT}@3x.png"
done
@pronebird
Copy link

Thanks for sharing! The only script that worked for me!

@dhiv-nitt
Copy link

How do i use this in react-native ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment