Wednesday, October 10, 2018

photo albums, macros, perl regex, browser regex, terminal clipboard, and photo galleries

Middle School was not kind to me.
A long time ago I scanned the photo album I assembled shortly after college and put the photos online. (For a weird time in the late 90s too many websearches for old friends just pointed back to that dang site) The thing is I scanned things at too low of a resolution, so I decided to redo the effort at 600 dpi and post them on my blog.

Over the year I've hacked up my blog system to be pretty friendly to post photos, especially with resizing images for web display, but keeping the fullsize images there as a link (since I finally realized it really was my canonical personal data warehouse.)

(I'm still enamored of my CSS hacky photo gallery system, which easily makes a nice compact display of the album with a minimum of setup)

Anyway, I reused all the file names from my original scans, which include a lot of metadata about people and places in the photos, so I wanted to go from the html my blog system generates for me, for example
<a href="/m/2018/10/10/049.c.mrs mclaughlin at prom toasting camera.jpg"><img src="/m/2018/10/10/049_560.c.mrs mclaughlin at prom toasting camera.jpg" border="0" width="560" height="441"></a>
<br><br>
and copy the filename as the caption underneath, ala:
<a href="/m/2018/10/10/049.c.mrs mclaughlin at prom toasting camera.jpg"><img src="/m/2018/10/10/049_560.c.mrs mclaughlin at prom toasting camera.jpg" border="0" width="560" height="441"></a> mrs mclaughlin at prom toasting camera<br> 
<br><br>

Once upon a time, I would have done this in a macro in a text editor - I feel like I used to care A LOT about how well an editor supported macros (it can get tricky, especially how you record a macro that uses a dynamic "find") but now it doesn't come up so much.

So my fallback plan was writing a perl script:
while($line = <STDIN>){
    chomp $line;
    print "$line\n";
    if($line =~ /^.*?\.\w\.(.*?)\.jpg/){
        print "$1<br>\n";
    }
}

The trick was being a bit lazy about putting things in temporary files - one thing that helped was the pbcopy command in MacOS Terminal, which can pipe stuff into clipboard.

So that would have got the job done, but then I remembered I had made a tool to help me do that in the browser: regexcellent which I write about here. In this case, the matcher was
^(.*?\.\w\.)(.*?)(\.jpg.*)$
and the output was
$1$2$3 $2<br> 
(the one thing I couldn't figure out was putting in \n's for line breaks, but not such a big loss)

Anyway, I'll be posting the results starting tomorrow.

Hope any of this was useful to someone! If only as notes to my future self...

No comments:

Post a Comment