Panorama to square images for Instagram #

Instagram recently added a feature to post up to 10 photos side by side. I saw someone cleverly used it to post a single panoramic photo. You split the panorama into square photos and then post them all at once to Instagram, which then arranges them side by side. Here's a quick & dirty script I wrote to split up my own panoramas into square photos. It uses a few Mac commands to get the size of the image, and ImageMagick to break up the images into smaller ones:

#!/bin/bash

if [ -z "$1" ]; then
    echo "Usage: $0 filename.jpg"
    exit
fi

filename="$1"

# Original image size
width=$(mdls -raw -name kMDItemPixelWidth "$filename")
height=$(mdls -raw -name kMDItemPixelHeight "$filename")

# Each of the square pieces will be 1/Nth the width
N=$[$width / $height]
if [ $N -gt 10 ]; then N=10; fi  # maximum 10 allowed by instagram

size=$[$width / N]
if [ $height -lt $size ]; then size=$height; fi

    
# Use the center of the x,y range
x_offset=$[$[$width - $size * N] / 2]
y_offset=$[$[$height - $size] / 2]


echo  "$filename : ${width}x${height}, $N parts"

if [ $x_offset -gt 0 ]; then
    echo "Wide image; truncating $[2 * $x_offset] pixels"
else
    x_offset=0
fi

if [ $y_offset -gt 0 ]; then
    echo "Tall image; truncating $[2 * $y_offset] pixels"
else
    y_offset=0
fi

for part in $(seq $[$N - 1] -1 0); do
    crop="${size}x${size}+$[${x_offset} + ${size}*${part}]+${y_offset}"
    echo "  part $part : $crop"
    convert "$filename" -crop "$crop" $part.jpg
done

I'm sure there are lots of things I could do better but I just wanted to get something working quickly.

Labels:

Emacs spaceline mode line #

Back in 2011 I posted my Emacs mode line configuration. At the time I was thinking it'd be nice to have a more modular way to define the mode line. A few weeks ago I rewrote my mode line configuration to use Spaceline, the mode line library used in Spacemacs. I made it match my tabbar:


...

Labels: ,

Tunnels everywhere #

Right now tunnel boring machines are expensive and we only use them for a few projects. If they were cheaper we'd have a lot more of them and use them for many more roads.

I've long wanted tunnels for lightweight freight transportation (see my blog post from 2005) but I'd also like tunnels for infrastructure in general — electricity, gas, water, gray water, cable tv, telephone land line, fiber optic internet, mail delivery, trash collection, etc. It's a shame that we have to dig up roads to install or fix any of these. It's a shame that I can't get gray water for my yard and am using drinking water to water my flowers. It's a shame that fiber optic internet access is so expensive to install. It's a shame that we have to see ugly power/telephone/cable lines everywhere. Also, a lot of this stuff would be better out of the weather.

Cheap tunnels would change a lot of things! I'm hoping Elon Musk will make this happen!

Labels:

Emacs Org mode 9 #

Org mode 9 was just released, and it changed the syntax for export blocks. I need to change:

#+begin_html
…
#+end_html

to

#+begin_export html
…
#+end_export

The Org mode changes file includes some elisp to change this. However, I couldn't get it to work, and I also wanted to change all my files, not run this elisp on one file at a time. Here are the commands I ran:

ack -l --type-add=org:ext:org --org '#.begin_html' | xargs -n 1 perl -pi -e 's/#\+end_html/#+end_export/'
ack -l --type-add=org:ext:org --org '#.begin_html' | xargs -n 1 perl -pi -e 's/#\+begin_html/#+begin_export html/'

I only needed this for html, but you may need to extend this for other types you use. See what else you use with:

ack --type-add=org:ext:org --org '#.begin_(html|ascii|latex|odt|markdown|md|org|man|beamer|texinfo|groff|koma-letter)'

Labels: ,

Custom fortune cookies #

Idea: when at at Chinese restaurant, use facial recognition and/or tap into vast databases of personal information linked to your credit card to gather lots of information about the people at the table, then use deep neural networks to write a custom fortune for each person, then use focused microwaves to print these on blank pieces of heat-sensitive paper embedded inside fortune cookies. Then when you get your fortune cookie, it'll be personalized just for you. Maybe it could be a targeted ad!

Labels: