Permalink
Browse files

Allow hard/soft/ref - linking to the original image, instead of copy

(Addresses issue wavexx#72)
  • Loading branch information...
hamishcoleman committed May 11, 2017
1 parent 759479d commit 357c0c5a196a90d66924aa753d4d90d8e6542deb
Showing with 56 additions and 3 deletions.
  1. +50 −3 fgallery
  2. +6 −0 fgallery.1
View
@@ -66,6 +66,8 @@ my $workers = 0;
my $sRGB = 1;
my $indexUrl = undef;
my @capmethods = ("txt", "xmp", "exif");
my $copy_method = 'copy';
my @copy_method_ok = qw(copy hard sym ref);
# support functions
@@ -332,6 +334,16 @@ sub parse_cap
return @capmethods;
}
sub parse_copy_method
{
my $opt = shift;
my $value = shift || 'hard'; # default to hard link
if (!isin($value, @copy_method_ok)) {
fatal("invalid image copy method: $value");
}
return $value;
}
sub print_version
{
print("fgallery $VERSION\n");
@@ -361,6 +373,7 @@ sub print_help
--no-sRGB do not remap preview/thumbnail color profiles to sRGB
--quality Q preview image quality (0-100, currently: $imgq)
--index url specify the URL location for the index/back button
--link-orig change images copy method (hard,sym,ref or copy)
});
exit(shift);
}
@@ -388,7 +401,9 @@ my ($ret, @ARGS) = GetOptions(
'min-thumb=s' => sub { @minthumb = parse_wh(@_); },
'no-sRGB' => sub { $sRGB = 0; },
'quality=i' => sub { $imgq = parse_int($_[0], $_[1], 0, 100); },
'index=s' => sub { $indexUrl = $_[1]; });
'index=s' => sub { $indexUrl = $_[1]; },
'link-orig:s' => sub { $copy_method = parse_copy_method($_[0], $_[1]); },
);
if(@ARGV < 2 || @ARGV > 3 || !$ret) {
print_help(2);
@@ -629,6 +644,39 @@ foreach my $props(@aprops)
}
$amp /= @files;
sub copy_source_file
{
my $file = shift;
my $fout = shift;
my @options;
push @options, '-L';
my %option = (
hard => '--link',
sym => '--symbolic-link',
ref => '--reflink',
);
if (defined($option{$copy_method}))
{
push @options, $option{$copy_method};
}
# symlinks need the right dest path - simplest is to give them an abs path
if ($copy_method eq 'sym')
{
$file = rel2abs($file);
}
sys('cp', @options, $file, $fout);
# these copy methods end up with a new inode
if ($copy_method eq 'copy' || $copy_method eq 'ref')
{
chmod(0600, $fout);
}
}
# 2nd pass: produce output files
sub process_img
{
@@ -649,8 +697,7 @@ sub process_img
progress::status($fbase);
# copy source file
sys('cp', '-L', $file, $fout);
chmod(0600, $fout);
copy_source_file($file,$fout);
# apply lossless transforms
if(!$keeporig)
View
@@ -131,6 +131,12 @@ Set the JPEG quality of the preview images to
The default is 90.
.It Fl -index Ar URL
Specify the URL location for the index and back buttons.
.It Fl -link-orig[=TYPE]
Change the method used to copy the original images. If this option is
not given, the method defaults to "copy". If the type is not specified
it sets the method to "hard". Otherwise the type must be one of "copy",
"hard", "soft" or "ref" - for normal copy, hard-linking, soft-linking or
ref-linking respectively.
.El
.Sh SEE ALSO
.Xr ImageMagick 1 ,

0 comments on commit 357c0c5

Please sign in to comment.