Images

A Hugo Image/Photo Gallery

I recently switch this site from Wordpress to Hugo - and the site with Danish content too. It was mostly easy and straight forward, but initially there was a few features missing (by the very nature of it being a static site) and some things I needed to look into once the switch had happened. One of these was a gallery function to present images (photos mostly). Gallery options…. There are various ways to have a gallery on a site, and one of the pains I had with wordpress, was changing strategies over time, which left me with several plugins needed to handle the historic gallery choices.

Batch converting JPG and PNG to WebP

I’ve been speed optimizing some of my personal sites, and one easy update is changing the images from being JPEGs and PNG images to the smaller WebP format. All the images I need to convert are usually in collections, where one folder at a time needs conversion and as some contain a lot of images, I needed a way to do it smartly. This is what I came up with:

Rotating an Image with Perl

Turning images is quite simple. In the example below an image is turned 90 degrees clockwise, wirtten to a file, turned another 90 degress and written to a file again. #!/usr/bin/perl -w use strict; use Image::Magick; my $image = Image::Magick->new(magick=>'JPEG'); my $x = $image->Read('test.jpg'); $x = $image->Rotate(degrees=>90); # 90 degress clockwise $x = $image->Write('test.90.jpg'); $x = $image->Rotate(degrees=>90); # Another 90 degress clockwise $x = $image->Write('test.180.jpg'); exit();

Converting between image formats with Perl

Changing files from one format to another is quite easy with a little bit of ImageMagick . In the example below a JPG image (test.jpg) is converted into a GIF-image (test.gif). To output in a different (ImageMagick supported ) format, just change the “image->Set” line. #!/usr/bin/perl -w use strict; use Image::Magick; my $image = Image::Magick->new(); # To explicitly set image format use this instead: # my $image = Image::Magick->new(magick=> 'JPEG'); my $x = $image->Read('test.

Reading Exif data with PHP

Within most photos from digital cameras besides the actual image, there’s a little ”information block” call EXIF data. If you have the correct PHP extension installed on your server – the one called ”exif” – it’s pretty easy to read the EXIF data and display them, as you like. First, let’s check if the extension is available? $load\_ext = get\_loaded\_extensions(); if (!in\_array(exif, $load\_ext)) { echo "Exif is NOT available"; } else { echo "Exif extension is available.