[Bash] Prep version 3
I use a fairly basic script that formats pictures, uploads them via Dropbox, and inserts paste-ready HTML code into my clipboard. With some minor modifications this script can be used on Linux, Windows (Cygwin), or OS X. Taking a break from animating sprites, I wanted to improve this script, in order to reduce my work. Currently I have to create the folder, move the images into it, and rename them appropriately. Really, fuck that. The first step is an epic onethree-liner (I will unpack it) that outputs the average number of unique image files per folder in my Dropbox/content/ folder:
#!bin/bash # Returns the average number of files. COUNT=0 for FOLDER in ./*; do # Aggregate $COUNT with the unique images in each folder. COUNT=`expr $COUNT + $(ls $FOLDER/*.jpg 2>/dev/null | wc -l)` done # Return an average by dividing count by the total folders within this one. echo `expr $COUNT / $(ls -1 | wc -l)`
From this I get:
[Mark][content] # ./av.sh 2
So eh, with that exercise out of the way, I revised the script. You invoke it with: prep $FOLDER $FILE1 $FILE2 $FILE3 ...
#!/bin/bash # Destination Dropbox folder. PUB=/cygdrive/c/Users/Mark/Dropbox/Public/content/ # Dropbox DUID. DUID=4144919 # Thumbnail folder. MED=m # Temp file for output into clipboard. TMP=.tmp # Images are are renamed numerically. COUNT=0 # First arg must be the folder. if [ ! -d $1 ] then mkdir -p $1/$MED fi # You can add up to six images at a time. # My average per folder is 2.3, so this is plenty /for me/. for i in $2 $3 $4 $5 $6 $7 $8 $9 $10 do COUNT=`expr $COUNT + 1` cp $i $1/$COUNT.jpg done cd $1 # Copy and resize images appropriately. cp ./*jpg $MED mogrify -quality 90 -resize 1000x+0+0 ./*.jpg mogrify -quality 90 -resize 540x+0+0 m/* for i in $(seq 1 $COUNT) do # Echo this string into the temp file, modified for each image. echo <a title=\"CHANGE ME\" href=\"http://dl.dropbox.com/u/$DUID/content/$1/$i.jpg\"> <img src=\"http://dl.dropbox.com/u/$DUID/content/$1/m/$i.jpg\" alt=\"\" /></a> >> $TMP done # Send the assembled string to the Windows clipboard. cat $TMP | putclip rm $TMP mv $(pwd) $PUB
Categorised as: linux, website
