Categories
WordPress

Hide featured image if it’s in the post

I’ve been running a photoblog at inphotos.org since 2005 on WordPress. (And thanks to writing this I noticed it’s 15 years old today!)

In that time WordPress has changed dramatically. At first I used Flickr to host my images, but after a short time I hosted the images myself. (Good thing too since Flickr limited free user accounts to 1000 images, so I wrote a script to download the Flickr images I used in posts.)

For quite a long time I used the featured image instead of inserting the image into the post content, but then about two years ago I went back to inserting the photo into the post. Unfortunately that meant the photo was shown twice, once as a featured image, and once in the post content.

The last theme I used supported custom post types, one of which was a photo type that displayed the featured image but hid the post content. It was an ok compromise, but not perfect.

Recently I started using Twenty Twenty, but after 15 years I had a mixture of posts with:

  • Featured image with no image in the post.
  • Featured image with the same image in the post.

I knew I needed something more flexible. I wanted to hide the featured image if it also appeared in the post content. I procrastinated and never got around to it until this evening when I discovered it was actually quite easy.

Copy the following code into the function.php of your child theme and you’ll be all set! It relies on you having unique filenames for your images. If you don’t then remove the call to basename(), and that may help.

function maybe_remove_featured_image( $html ) {
        if ( $html == '' ) {
                return '';
        }
        $post = get_post();
        $post_thumbnail_id = get_post_thumbnail_id( $post );
        if ( ! $post_thumbnail_id ) {
                return $html;
        }

        $image_url = wp_get_attachment_image_src( $post_thumbnail_id );
        if ( ! $image_url ) {
                return $html;
        }

        $image_filename = basename( parse_url( $image_url[0], PHP_URL_PATH ) );
        if ( strpos( $post->post_content, $image_filename ) ) {
                return '';
        } else {
                return $html;
        }
}
add_filter( 'post_thumbnail_html', 'maybe_remove_featured_image' );

The post_thumbnail_html filter acts on the html generated to display the featured image. My code above gets the filename of the featured image, checks if it’s in the current post and if it is returns a blank string. Feedback welcome if you have a better way of doing this!

Categories
Linux

Rsync between Mac and Linux

99.999999% of my readers can probably ignore this one, but if you are of the small minority who use Rsync and have Mac and Linux computers in your home you’ll want to read this.

I have Plex running on a Raspberry Pi for my music. I have a large mp3 folder. Too large to run Syncthing on it unfortunately, but an occasional rsync is perfectly fine.

I thought it worked fine until I quickly realised it was syncing the same files over and over again. It turns out the Mac and Linux machines I’m using have different ideas about character sets their filenames are stored in. A file with an accented character on the Mac is completely different to one that looks the same on the Linux box.

The solution took a while for me to find but it’s very simple. Rsync has an option named --iconv to convert between character sets!

The solution was embarrassingly simple: Much due to a comment I read when researching the problem, I thought you were supposed to specify the character set in the order of transformation; but it seems as that is not the correct syntax. Rather, one should always use --iconv=utf-8-mac,utf-8 when initialising the rsync from the mac, and always use --iconv=utf-8,utf-8-mac when initialising the rsync from the linux machine, no matter if I want to sync files from the mac or linux machine.

Then it works like magic!

EDIT: Indeed, sometimes, checking the manual page closely is a good thing to do. Here it is, black on white:

--iconv=CONVERT_SPEC
              Rsync  can  convert  filenames between character sets using this
              option.  Using a CONVERT_SPEC of "." tells rsync to look up  the
              default  character-set via the locale setting.  Alternately, you
              can fully specify what conversion to do by giving a local and  a
              remote   charset   separated   by   a   comma   in   the   order
              --iconv=LOCAL,REMOTE, e.g.  --iconv=utf8,iso88591.   This  order
              ensures  that the option will stay the same whether you're push-
              ing  or  pulling  files.

Categories
Photography

HOWTO: Square Instagram images with white borders

I noticed that a lot of Instagram users, such as Alan Schaller to name but one, were posting images with thick white borders to make their images into the square images that Instagram favours. I like the striking look these images have in the Instagram gallery.

I wondered for some time about the best way of adding this border and from brief searches there are apps that will add the border but my workflow involves Lightroom so I wanted to integrate the border making into my export process.

I work on a Mac, and already have ImageMagick installed so I knew a little shell scripting would probably go a long way.

A couple of searches later, and I found this page describing how to use ImageMagick to create a floating image within a square canvas without changing the aspect ratio of the image.

Instagram resizes to 1080px wide so by using the following code I could make a rectangular image into a square:

convert -background white -gravity center input.jpg \
     -resize 1080x1080 -extent 1080x1080 result.jpg

Here’s an example from my street photo today. See it on Instagram here.

Once I could do that, the rest was simple. I have a Lightroom export for Instagram images that resizes them and places them in a folder where they are synced automatically with my phone using Syncthing.

Export actions have a “post processing” section where Lightroom can call an external script. I created the following script, made it executable with chmod a+x add_instagram_border.sh and added to Lightroom using “Open in Other Application”.

#!/bin/sh

# Square and add white borders to images.
# https://odd.blog/

for i in "$@"
do
    /usr/local/bin/convert -background white -gravity \
        center "$i" -resize 1080x1080 -extent 1080x1080 \
        /tmp/out.jpg
    mv /tmp/out.jpg "$i"
    open "~/Sync/Instagram"
done

The script goes through the exported images from Lightroom, adding borders to them, and then at the end opens the folder in Finder for review.

Hopefully this will be useful to someone else. If you add borders to your images, how do you do it?

Categories
Amiga

PiMIGA: Amiga on the Pi

The Commodore Amiga was an amazing 16 bit computer of the 80’s and 90’s and is still used today by people who love the system.

WinUAE is the best Amiga emulator for modern systems and it has been ported to many operating systems. FS-UAE is a great port I use on Mac and Amiberry or Amibian use the uae4arm port that runs on Raspberry Pi boards.

To load games and apps on the Amiga you used 3.5 inch discs but if you had a hard disk back then the Amiga supported it. I never did so I put up with the relatively slow loading of the discs.

As I have been spoiled by much faster loading of modern systems, loading games from discs in an emulator soon became a bore. Many games used to (slowly) load an intro with thumping music and an animation, but after hitting fire on my joystick I’d be prompted to “Enter disc 2” for yet more loading.

Enter WHDLoad, a system that patched games so they could be loaded from a hard disk image. It sounds great in theory but over the years I could never get it working the way I wanted. I just wanted to see a nice Workbench desktop UI with an disk image of games to play around in.

I’m not the only one apparently. Through this video on alternative operating systems for the Raspberry PI I found out about PiMIGA. It’s a 32GB disk image you burn to SD card for RPI 3 and 4 and when booted up presents a rather nice Workbench desktop with lots of games and apps. BTW, the password is ViWsC7oU3.

It’s based on Amiberry, and uses WHDLoad of course and everything is set up for you!

I haven’t tested it yet myself. My RPI3 is busy running Plex, Backuppc and Pihole but I want to get an RPI4 to give it a go!

Here’s a word of warning however. The video above shows a virus checker running and it finds a couple of viruses that are removed (in Amiga apps) so I would isolate the Raspberry PI device from the rest of your network if you can. Use the guest network of your router perhaps or just leave the device offline.

An alternative to PiMIGA is AmiKit which appears to do something similar but runs on Windows, Linux and Mac (and RPI4 with some fiddling around) and even lets you launch Windows, Linux or Mac apps from within Workbench. It looks rather nice!

Categories
C64

Memento Mori

remember that you die

Memento Mori is a stunning Commodore 64 demo released by Genesis Project that won first place at the Function 2020 demo party recently. The picture above was shared by Raistlin/G*P on Twitter saying:

Razorback delivered this stunning piece for Memento Mori. This is a 408 pixel wide multicolour bitmap that we scrolled, right through the side borders, at 25fps, streaming from disk as we went. A world first on C64 🙂

Raistlin/G*P

Watch it here on Youtube!

Categories
Music

James Last plays the Beatles

In the mid 80’s I found a cassette tape of Beatles music played by the James Last orchestra. While I sort of knew some of the music this was the first time I heard many of the songs and I preferred this orchestra version to the original!

The next time the Beatles would intrude on my life would be when I watch Red Storm for the first time in the early nineties.

I guess I have a thing for instrumental Beatles music. 🙂

Categories
Games

Masters of the Universe Barbarian Style

A long time ago in 1987 a game called Barbarian made it’s way to the popular computers of the time. It featured brawny characters fighting to the death to rescue the scantily clad princess (or some such nonsense, game stories didn’t make much sense back then).

It was a great game with memorable music, fluid graphics, gruesome bloody moves and a goblin that would kick the head of your decapitated foe off the side of the arena. The gameplay got boring with time of course but and it was probably more infamous for the cover photo than anything else..

Anyway, after the short history lesson, I discovered that Andrea Baldiraghi announced the release of a new Masters of the Universe game on pico8. It’s inspired by Barbarian as Andrea says on the game homepage.

It has your favourite Masters of the Universe characters and even a rendition of the theme toon. In my first fight I managed to chop the head off Skeletor but the second devolved into a bloody fight to the end when I exhausted my opponent.

It’s embedded above, give it a go. Press Z to attack, X to defend and use the cursor keys to move!

Categories
Ireland

How many cars are on the road?

If you go along to the Transport Infrastructure Ireland website right now you’ll find a map of Ireland with lots of green dots.

These are the locations of cameras recording the volume of traffic on the road. It’s been interesting looking at some of the roads around Cork during the last year. Here are a few charts of traffic on the N20 between Blarney and Cork.

In January traffic maxed out at 1200 vehicles a day in the early morning with a similar bump in the evening.
February was similar, with slightly less vehicles per day.

The Covid-19 Lockdown bit in March. Schools closed on March 12th, pubs closed soon after. Most people who could were working from home. It made a big difference to daily traffic into Cork. From a high of 1200 vehicles in January to 400 in April.

In March only 800 vehicles a day made the journey into Cork. The 2km rule was introduced.
April was worse. The number of vehicles halved. Only 400 vehicles made the journey.
There was a very slight increase in traffic in May to 500 vehicles a day.
June saw a return to March numbers. 800 vehicles a day.
July was similar. Slightly more than 800 vehicles a day.
August isn’t over yet but numbers are slightly down again to less than 800 vehicles a day. Schools return at the end of the month so that will probably make a small bump.

How does this compare to last year? Here are the charts for July and August 2019.

July 2019 when almost 2000 vehicles travelled the road between Blarney and Cork.
August 2019 when Irish people went abroad and the country was noticeably quieter. 1100 vehicles a day.

It’s interesting to see those charts. The lockdown caused a huge drop in traffic as expected. Emissions from cars were down this year of course but agriculture remained the same so our impact on the environment didn’t change much. It’ll probably be worse as people use their cars rather than take public transport.

Out of curiosity I looked at the traffic volume going into Dingle from the Inch Strand side of the peninsula for July this year and last year. There wasn’t much of a change. 500 cars a day passed there in 2020 while only an extra 100 cars made the journey in 2019. They’ll be happy about that in Dingle!

Categories
Ireland

Anyone for Takeaway Pints?

Along with what seemed like a large portion of the country I stayed in Dingle recently. The town was packed. We stayed in a B&B on the edge of town and every day around noon the road outside was a traffic jam of cars snaking through the town. Most people wore masks in the shops but of course there were a few rat lickers too.

I did notice that a lot of people had several empty pint glasses on their tables, and while they may have eaten a €9 meal there was no sign of food. I spotted a happy young couple cross the road with plastic glasses of beer and sit down by the statue of Fungi. It was upsetting given what’s happening with Covid-19.

Now we’re in lockdown again. It’s not the same lockdown we experienced from March onwards but people became lax, and the virus made it’s way into factories. Multiple outbreaks in meat processing plants locked down 3 counties last week. Yesterday the news nationally wasn’t good:

  • 1 death and 190 cases confirmed.
  • 76 are men and 111 are women
  • 75% are under 45 years of age
  • 75 are confirmed to be associated with outbreaks or are close contacts of a confirmed case
  • 14 cases have been identified as community transmission
  • 48 are in Kildare, 46 in Dublin, 38 in Tipperary, 20 in Limerick, 7 in Clare and the rest of the 31 cases are in Carlow, Cork, Kerry, Kilkenny, Laois, Louth, Meath, Offaly, Waterford, Wexford and Wicklow.

And so the restrictions:

  • All outdoor events will be limited to 15 people, down from 200, under strict new limits on public gatherings agreed this afternoon.
  • Under the restrictions that will remain in place until 13 September at the earliest, indoor events will be limited to six people, reduced from 50, except for businesses such as shops and restaurants, which are subject to separate rules.
  • Weddings will be exempt from the new restrictions, meaning they can go ahead with 50 people.
  • The measures agreed by Cabinet will mean that matches and other sporting fixtures will have to take place behind closed doors.
  • Gardaí will be given new powers to enforce rules around social gatherings, particularly in restaurants or bars serving food, and in private homes.
  • Under the measures agreed by Cabinet, people will be advised to work from home and to avoid using public transport, unless absolutely necessary.

Which leads some to say the GAA should encourage weddings at their matches so 50 people can watch.

Still confused, here’s a clear explanation.

These graphs are not good are they?

Schools open soon. Hopefully we can reduce the community spread or we’ll be closing schools within a month.

Oh yes, watch out for Storm Ellen tonight. There’s a status red warning for Cork!

Categories
Linux

One of those rare bugs

I can’t login to my Raspberry PI3. When I ssh into it the password is rejected. When I plugged a keyboard and HDMI cable in the login would fail silently at first and then after reboot it would tell me the password was wrong.

Fearing the worst, that the small machine had been hacked, I plugged it out and attempted to go into single user mode but even that didn’t work. I tried various cmdline.txt changes, I saw an odd message saying:

sh: can't access tty; job control turned off

That wasn’t the worst. I even managed to generate a kernel panic once!

When I was just about ready to give up I plugged in the HDMI cable again and saw a strange libcrypt error show up.

/sbin/sulogin error while loading shared libraries: libcrypt.so.1: cannot open shared object file: no such file or directory

A quick search for that message brings me to the one thread on the Internet about it.

Unfortunately, I don’t have another Linux machine handy to copy libc6 from but I do have a backup of the SD card and that worked. I made a backup with Disk Utility (yes, don’t sneer, I can use dd too) and after making a new backup I restored the old backup with Etcher.

The last time I did an apt upgrade was just before a recent trip where I was depending on the RPI3 for my Plex music. Luckily the Plex server hadn’t restarted in that time and must have been using the old libc6!

Another tool that was useful here was ext4fuse which I installed through Homebrew. It’s even possible to mount an ext4 partition from an SD card image by first mounting the boot partition with Disk Utility, checking the device with df -h and then using the very next device number like this:

ext4fuse /dev/disk9s2 /Volumes/rpi -o allow_other

Read only access to the Raspberry PI/Linux part of the image! Strangely enough it doesn’t show in Finder but df shows it is mounted.

Now to make a new SD card backup before I update anything else with apt.