Compare commits
2 Commits
d626278969
...
75be99058e
Author | SHA1 | Date | |
---|---|---|---|
|
75be99058e | ||
|
0352b0d720 |
55
flickr.sh
Normal file
55
flickr.sh
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
usage(){
|
||||||
|
cat << HEREDOC
|
||||||
|
$0 [-h] [MAXFILE] [TAG]
|
||||||
|
This script loads and merges images based on random words
|
||||||
|
-h this help
|
||||||
|
MAXFILE Limit number of images to compose
|
||||||
|
TAG Don't pick tag randomly
|
||||||
|
HEREDOC
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
panic(){ echo $@; exit 2; }
|
||||||
|
[[ $1 == "-h" ]] || [[ $1 == --help ]] && usage
|
||||||
|
|
||||||
|
cd $( dirname $0 )
|
||||||
|
MAXFILE=${1:-20}
|
||||||
|
TAG=${2}
|
||||||
|
TMPFILE=$(mktemp)
|
||||||
|
|
||||||
|
# Search images
|
||||||
|
for i in {1..99}; do
|
||||||
|
RAND=$( echo | awk ' { srand(); print int(rand() * 234937 ) } ')
|
||||||
|
WORD=$(awk "NR==$RAND" /usr/share/dict/words);
|
||||||
|
[ -n "$TAG" ] && WORD=$TAG
|
||||||
|
URL="https://api.flickr.com/services/feeds/photos_public.gne?tags=$WORD&tagmode=any";
|
||||||
|
IMGLIST=($(curl -s "$URL" | grep '"enclosure"'| sed -r 's_^.*href="(.*jpg)".*$_\1_' | grep "^http"))
|
||||||
|
[ $i -eq 2 ] && [ -n "$TAG" ] && panic "Failed to load tag" ]
|
||||||
|
[ 2 -gt ${#IMGLIST[@]} ] && continue
|
||||||
|
break;
|
||||||
|
done
|
||||||
|
|
||||||
|
# Download images
|
||||||
|
mkdir -p images
|
||||||
|
for i in $( seq 0 $(( ${#IMGLIST[@]} -1 )) ); do
|
||||||
|
IMGURL="${IMGLIST[$i]}"
|
||||||
|
[[ ${IMGLIST[$i]} =~ ^http ]] || continue
|
||||||
|
wget -q "$IMGURL" -P images
|
||||||
|
[[ O -eq $? ]] && FILELIST+=(images/$(basename ${IMGLIST[$i]} ) )
|
||||||
|
[ $i -gt $(( $MAXFILE -2 )) ] && break
|
||||||
|
done
|
||||||
|
|
||||||
|
# Create synthetic image
|
||||||
|
mkdir -p synthesis
|
||||||
|
SYNTH_NAME="synthesis/$(date +%s)-$WORD.jpg"
|
||||||
|
SRC=${FILELIST[0]}
|
||||||
|
#copy the first image
|
||||||
|
cp $SRC $SYNTH_NAME
|
||||||
|
for i in $( seq 1 $(( ${#FILELIST[@]} -1 )) ); do
|
||||||
|
composite ${FILELIST[$i]} $SYNTH_NAME -gravity center -compose difference "$SYNTH_NAME"
|
||||||
|
done
|
||||||
|
|
||||||
|
[ ! -d logs ] && mkdir -p logs
|
||||||
|
echo "File generated with word $WORD and ${#FILELIST[@]} images: file://$PWD/$SYNTH_NAME" | tee "logs/$(basename $SYNTH_NAME)"
|
||||||
|
echo "${FILELIST[@]}" | tee -a "logs/$(basename $SYNTH_NAME)"
|
||||||
|
|
@ -49,7 +49,7 @@ for i in $( seq 1 $(( ${#FILELIST[@]} -1 )) ); do
|
|||||||
composite ${FILELIST[$i]} $SYNTH_NAME -gravity center -compose difference "$SYNTH_NAME"
|
composite ${FILELIST[$i]} $SYNTH_NAME -gravity center -compose difference "$SYNTH_NAME"
|
||||||
done
|
done
|
||||||
|
|
||||||
mkdir logs
|
mkdir -p logs
|
||||||
echo "File generated with word $WORD and ${#FILELIST[@]} images: file://$PWD/$SYNTH_NAME" | tee "logs/$(basename $SYNTH_NAME)"
|
echo "File generated with word $WORD and ${#FILELIST[@]} images: file://$PWD/$SYNTH_NAME" | tee "logs/$(basename $SYNTH_NAME)"
|
||||||
echo "${FILELIST[@]}" | tee -a "logs/$(basename $SYNTH_NAME)"
|
echo "${FILELIST[@]}" | tee -a "logs/$(basename $SYNTH_NAME)"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user