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:
#!/bin/sh MED=m/ SML=s/ mkdir -p $MED $SML for file in $(find . -iname "*.jpg"); do cp $file $MED cp $file $SML done 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:
- Move the given folder into my Dropbox folder.
- Construct the URL code I use and ready it for pasting. Typical code is:
<a title="Click to view larger size" href="https://ix.bhalash.com/1466601748/1.jpg"> <img src="https://ix.bhalash.com/1466601748/1.jpg" alt="" /> </a>
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] # pwd /home/mark/1466601748 [mark] # basename $(pwd) 1466601748
Call me stupid. So, #1 is the easiest to achieve:
[mark] # 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:
#!/bin/sh USERID=4144919 POSTID=$(basename $(pwd)) echo \<a title=\"Click to view larger size\" href=\"http\:\/\/ix.bhalash.com\/u\/$USERID\/content\/$POSTID\/1.jpg\"\> \\ \<img src=\"http\:\/\/ix.bhalash.com\/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.