Skip to content

Instantly share code, notes, and snippets.

@alikaragoz
Created January 1, 2013 15:25
Show Gist options
  • Save alikaragoz/4428118 to your computer and use it in GitHub Desktop.
Save alikaragoz/4428118 to your computer and use it in GitHub Desktop.
Blog post
#!/bin/sh
# We get the path of the current directory and we move in it
DIR=$(cd "$(dirname "$0")"; pwd)
cd $DIR
# Creating full and thumbnails images folders
FULL_IMG="full"
THUMB_IMG="thumb"
mkdir $FULL_IMG
mkdir $THUMB_IMG
# Creating a preliminary .md file with the images
for file in *.jpg ; do echo "![](/photos/"$file")" >> post.md ; done
# Cpying files
cp *.jpg $FULL_IMG/
cp *.jpg $THUMB_IMG/
# Resizing the image to 1200px width
cd $FULL_IMG
mogrify -resize 1200x *.jpg
jpegoptim --max=80 *.jpg
# Resizing the image to 460x320 width and gravity crop in the center
cd ../$THUMB_IMG
mogrify -resize 460x320^ -gravity center -crop 460x320+0+0 *.jpg
jpegoptim --max=70 *.jpg
for file in *.jpg ; do mv $file `echo $file | sed 's/.jpg/\_thumbnail.jpg/'` ; done
# Transfering the photos inside the public directory of the rails app
cd ../
scp -r $FULL_IMG/*.jpg root@server.net:/home/user/site.net/public/photos/
scp -r $THUMB_IMG/*.jpg root@server.net:/home/user/site.net/public/thumbnails/
# Finally we remove the file we just created
rm -rf $FULL_IMG $THUMB_IMG
# Exiting the terminal
osascript -e 'tell application "Terminal" to quit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment