Skip to content

Commit

Permalink
Allow hard/soft/ref - linking to the original image, instead of copy
Browse files Browse the repository at this point in the history
(Addresses issue wavexx#72)
  • Loading branch information
hamishcoleman authored and kensanata committed Oct 25, 2017
1 parent b6db8ad commit ba3bf06
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
54 changes: 51 additions & 3 deletions fgallery
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ my $galleryTitle = "";
my $galleryDescription = "";
my $galleryUrl = "";
my $update = 0;
my $copy_method = 'copy';
my @copy_method_ok = qw(copy hard sym ref);


# support functions
sub fatal
Expand Down Expand Up @@ -335,6 +338,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");
Expand Down Expand Up @@ -364,6 +377,7 @@ sub print_help
--min-thumb WxH minimum thumbnail size ($minthumb[0]x$minthumb[1])
--no-sRGB do not remap preview/thumbnail color profiles to sRGB
--quality Q preview image quality (0-100, currently: $imgq)
--link-orig change images copy method (hard,sym,ref or copy)
--index url specify the URL location for the index/back button
--title "Foo" the title to use for Facebook and Twitter previews
--description "bar" the description to use for Facebook and Twitter previews
Expand Down Expand Up @@ -403,7 +417,9 @@ my ($ret, @ARGS) = GetOptions(
'index=s' => sub { $indexUrl = $_[1]; },
'title=s' => sub { $galleryTitle = $_[1]; },
'description=s' => sub { $galleryDescription = $_[1]; },
'url=s' => sub { $galleryUrl = $_[1]; });
'url=s' => sub { $galleryUrl = $_[1]; },
'link-orig:s' => sub { $copy_method = parse_copy_method($_[0], $_[1]); },
);

if(@ARGV < 2 || @ARGV > 3 || !$ret) {
print_help(2);
Expand Down Expand Up @@ -678,6 +694,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
{
Expand All @@ -698,8 +747,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)
Expand Down
6 changes: 6 additions & 0 deletions fgallery.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 ,
Expand Down

0 comments on commit ba3bf06

Please sign in to comment.