Fixpoint

2019-11-16

Blogging photos and chat logs: some handy scripts

Filed under: Software — Jacob Welsh @ 20:37

For last night's article I had to pay the debt of having deferred my ever so carefully planned dig into photo blogging for quite so long. I started from Popescu's recipe and made it into a script, including doing the necessary jiggling so I wouldn't have to recall the details every time.

One detail I wasn't sure about was the function of the "size-large" and "wp-image-###" classes on the <img> tag, so I left them out. If I wanted to style an individually numbered image, I can't imagine why I'd want to do it in a global CSS file rather than a local style attribute but perhaps there's some other reason. Ideally I should have asked in advance.

Without further ado, the blog-photos script:(i)

#!/bin/sh
echo -n "Output file prefix: "
read pfx
root="/wp-content/uploads/`date +%Y/%m`"
let cnt=0
for f in "$@" ; do
	let cnt++
	echo -n "<a href=\"$root/$pfx-$cnt.jpg\">"
	echo "<img src=\"$root/$pfx-$cnt-720px.jpg\" alt=\"$pfx-$cnt\" title=\"$pfx-$cnt\" width=\"720\" class=\"aligncenter\" /></a>"
	echo # paragraph break for spacing between photos
	convert "$f" -auto-orient -geometry 1920 "$pfx-$cnt.jpg"
	convert "$f" -auto-orient -geometry 720 "$pfx-$cnt-720px.jpg"
done

The chief dependency here is of course ImageMagick. Typical usage, from a directory full of pre-selected images:

blog-photos *.JPG > draft.html

You could of course use "tee" instead of redirection if you'd like to see the progress. Once you've uploaded the resulting images to the proper directory, paste the draft as a new article (I like "xclip" for this; of course a GUI text editor would work too) and load the preview; this allows you to identify image numbers by mouseover so as to find where to put your text.

Next up, a simpler one for importing chat logs in the presently prevailing style from a browser, with proper escaping of special HTML characters, logotron2wp:

#!/bin/sh
sed -re 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/^([^: ]*)/<strong>\1<\/strong>/'

Come to think of it, the first three substitutions there also work for any sort of code import that might contain those pesky &<> characters - such as this one right here.

The comment box awaits any questions, comments, flames etc.

  1. And now we'll get to see how badly long code lines will render... [^]

1 Comment »

  1. [...] stuff. Except that I wanted to try out Mircea Popescu's image processor for blog articles, and also jfw's version of the same. Except! It turns out the box I'm using for publishing doesn't have Image Magick, [...]

    Pingback by A Little Bit of TinyScheme, a Lot of Cozonac « The Whet — 2019-11-25 @ 14:30

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by MP-WP. Copyright Jacob Welsh.