Prep version 1

For reasons-reasons other than convenience-that I would not be able to fully articulate should you choose to put a gun to my head, I store my website’s files (WordPress), database and content images separately. I guess if one’s data centre is bombed then the other two will be okay? Well, back to the convenience. I post a great many images to this blog; for the aforementioned convenience, I store my images in Dropbox. I can quickly and easily move, rename or alter images on my blog without having to piss about with FTP. Now, beyond handling the core image processing I don’t want to get bogged down in resizing, foldering, renaming and uploading all of those files. Because of this I script the action, but my current script only creates preview and thumbnail sizes:


mkdir -p $MED $SML 

for file in $(find . -iname "*.jpg"); do 
    cp $file $MED 
    cp $file $SML 

mogrify -quality 90 -resize 540x540+0+0 $MED*.jpg 
mogrify -quality 90 -gravity center -crop 256x256+0+0 $SML*.jpg 

exit 0

Today I want to add three two new features to it:

  1. Move the given folder into my Dropbox folder.
  2. Construct the URL code I use and ready it for pasting. Typical code is:
<a title="Click to view larger size" href="">
    <img src="" alt="" />

For both steps, I need the ability to output

only the name of the current directory I am working in, since this directory will be named according the number to the post. In the case of this blog post the folder name will be 1466601748. I spent about three hours fucking about with awk, sed, Google and pipes before I discovered a very simple one-liner that delivers the folder name unto me:

[mark][1466601748] # pwd 
[mark][1466601748] # basename $(pwd) 

Call me stupid. So, #1 is the easiest to achieve:

[mark][1466601748] # 
mv $(pwd) ~/Dropbox/Public/content

Step 2, generating the URL code, will be interesting, although trivial too. It seems like the easiest way is to echo the URL while I insert the post number and then stick the hot, steaming result into my clipboard. This works fine…but my sense of neatness is screaming at me that there is probably a more elegant way to achieve my goal:


POSTID=$(basename $(pwd))

echo \<a title=\"Click to view larger size\" href=\"http\:\/\/\/u\/$USERID\/content\/$POSTID\/1.jpg\"\>   \\
\<img src=\"http\:\/\/\/u\/$USERID\/content\/$POSTID\/m\/1.jpg\" alt=\"\" \/\/>\< \/a\> | xclip -sel clip</a> 

exit 0

Short version: Escape the shit out of everything and let God judge the survivors. Using $USERID instead of a hard-set user number gives me a little bit of portability for you, the consumer.

Enjoy. /smrt

Mark Grealish

Dashing brigand, handsome rapscallion, father, crazy cat lady and the world's greatest lover and liar, living in Dublin, Ireland.

Have your say on 'Prep version 1'

Your email address will not be published. Required fields are marked *