# Album Plugin: images/heic
# For info: 'album -plugin_info images/heic'
# For usage:  'album -plugin_usage images/heic'
use strict;		# Not required, but recommended

my $DESCRIPTION = << 'DESCRIPTION';
Handles Apple's crappy HEIC internal proprietary format that keeps
getting saved to the rest of the world.  No mainstream browsers support
heic, and even Safari didn't support it for some time.  When iPhone's
export photos, they convert to JPG, but often that conversion gets
unintentionally skipped, and we end up with HEIC photos.

As a simple solution, we at least make sure the medium image is not HEIC,
but the full is still the original.

DESCRIPTION

sub start_plugin {
	my ($opt) = @_;

	my $ret = {
		author      => 'David Ljung Madison',
		href        => 'http://MarginalHacks.com/',
		version     => '1.0',
		description => $DESCRIPTION,
	};

	# Setup the hooks
 	album::hook($opt, 'medium',  \&medium);

	return $ret;
}


sub medium {
	my ($opt, $hook,  $dir, $obj, $file, $full_path) = @_;

	# Just cheat and change the actual names of the images
	my $mdm_type = $opt->{medium_type} || $opt->{type} || 'jpg';
	$obj->{medium}{file} =~ s/\.heic$/.$mdm_type/i;
	$obj->{medium}{path} =~ s/\.heic$/.$mdm_type/i;
	return undef;
}


# Plugins always end with:
1;
