Thursday, November 24, 2016

photocap.php : offline photo captioning hack

So, I haven't posted much lately, I was in Malaysia for a bit under two weeks.

One thing about vacations to Malaysia - lots of pictures...

(If for some reason you want to see more, go here and start clicking through up to the 21st)

Anyway, in the current social media world, I tend to double post; I put photo galleries on FB, where friends and family are more likely to see it and comment, but I also like keeping them on my blog as their permanent home.

FB has polished photo gallery editing, but my blog doesn't. Also, where Internet was spotty (like at our resort; downloading was fine but uploading was terribly slow) or non-existent, I wanted a tool to edit captions offline, one that made it easy to later put the photos onto FB and my site. For FB, it's still pretty manual copy and pasting, but it goes fast. (Haven't researched if there are any better ways to automate making albums with captions, but frankly I do it so rarely it might not be worth more dev time.) For my blog I can just generate the appropriate HTML and copy and paste (modulo some search and replace fiddling I do for my blogs way of handling thumbnails and upload folders)

PHP has a convenient built-in webserver, from a shell run 
php -S localhost:8000
(or whatever port you like)

So here's the simple editor I came up with, a one-file-wonder. It has a bit of Javascript that I kept vanilla (I do like when everything can just be one file), it writes out a tab delimited CAPTIONS.txt file, and it stores deleted photos in a folder called "killem".

Below is a link to the code for my future reference, I just need to copy and paste it into a file named "photocap.php" in the same folder as all the photos. I ran into a few PHP quirks, like I had to encode filenames rather than use them as straight up keys because "." is not allowed in a key.

Also the code is pretty rough, but that's what I get for hacking on a sunny beach while drinking...

I published the code at github.

No comments:

Post a Comment