Last active
August 29, 2015 14:17
-
-
Save Jlaird/8918a497a8e49bdbe886 to your computer and use it in GitHub Desktop.
Image Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
limit=5000 | |
counter=0 | |
while [ $counter -lt $limit ]; do | |
image=$(head -n 1 images.txt) | |
echo "$(tail -n +2 images.txt)" > images.txt | |
if [[ -z "$image" ]];then | |
echo done | |
exit 1 | |
fi | |
imagepaths=(${image//,/ }) | |
image=(${imagepaths[0]}) | |
originalpath=(${imagepaths[1]}) | |
wget "$image" | |
imagepath=(${image//\// }) | |
arr_last=$((${#imagepath[@]}-1)) | |
localfilename=${imagepath[$arr_last]} | |
if [ -a "$localfilename" ]; then | |
echo move $localfilename | |
name=(${image//\// }) | |
#get the nice file name and original path | |
originalpath=(${originalpath//\// }) | |
arr_last=$((${#originalpath[@]}-1)) | |
filename=${originalpath[$arr_last]} | |
unset originalpath[$arr_last] | |
arr_last=$((${#originalpath[@]}-1)) | |
unset originalpath[$arr_last] | |
mediapath=$(IFS=/ ; echo "${originalpath[*]}") | |
ex=(${filename//./ }) | |
arr_last=$((${#ex[@]}-1)) | |
ex[$arr_last]="png" | |
pngfilename=$(IFS=. ; echo "${ex[*]}") | |
#echo "media path: $mediapath" | |
#echo "local files name: $localfilename" | |
#echo "nice file name: $filename" | |
#echo "nice png file name: $pngfilename" | |
#echo "move: $localfilename /cdn/media/$mediapath/original/$filename" | |
mkdir -p /cdn/media/$mediapath/original/ | |
/usr/local/bin/convert /data/$localfilename -gravity center -thumbnail 1920 PNG32:/cdn/media/$mediapath/$pngfilename | |
mv $localfilename /cdn/media/$mediapath/original/$filename | |
else | |
echo $image >> error | |
fi | |
echo "counter: $counter" | |
let counter++ | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment