Minor bugs
Cropping should be avoided if the image is the same size also, not just if it is smaller. I was using a minimum of 2 outputs while testing on my desktop. Revert that to 1. Remove trailing tabs.
This commit is contained in:
parent
31fc3ceff3
commit
640dd8d2d9
|
@ -11,7 +11,7 @@ use AnyEvent::Sway;
|
||||||
our $s = AnyEvent::Sway->new();
|
our $s = AnyEvent::Sway->new();
|
||||||
|
|
||||||
our $o = $s->get_outputs->recv();
|
our $o = $s->get_outputs->recv();
|
||||||
die "No outputs detected.\n" unless (scalar(@$o) > 1);
|
die "No outputs detected.\n" unless (scalar(@$o));
|
||||||
|
|
||||||
sub usage()
|
sub usage()
|
||||||
{
|
{
|
||||||
|
@ -74,10 +74,10 @@ sub choose_image
|
||||||
push(@i,$_);
|
push(@i,$_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $i[rand(scalar(@i))] || return undef;
|
return $i[rand(scalar(@i))] || return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_size
|
sub get_size
|
||||||
{
|
{
|
||||||
my $target = shift;
|
my $target = shift;
|
||||||
|
@ -102,15 +102,15 @@ sub crop
|
||||||
|
|
||||||
my $cropped = $image;
|
my $cropped = $image;
|
||||||
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$1-cropped.$2#;
|
$cropped =~ s#^.*/([^/]*)\.([^\.]+)$#$1-cropped.$2#;
|
||||||
|
|
||||||
use Image::Magick;
|
use Image::Magick;
|
||||||
my $im = Image::Magick->new();
|
my $im = Image::Magick->new();
|
||||||
|
|
||||||
$im->Read($image);
|
$im->Read($image);
|
||||||
my ($iw, $ih) = $im->Get("columns", "rows");
|
my ($iw, $ih) = $im->Get("columns", "rows");
|
||||||
|
|
||||||
# Return full size if it is smaller in either dimension then the output
|
# Return full size if it is smaller in either dimension then the output
|
||||||
if ($iw < $ow || $ih < $oh) {
|
if ($iw <= $ow || $ih <= $oh) {
|
||||||
print "Not cropping $image because it is too small\n";
|
print "Not cropping $image because it is too small\n";
|
||||||
$cropped =~ s#-cropped\.([^\.]+)$#\.$1#;
|
$cropped =~ s#-cropped\.([^\.]+)$#\.$1#;
|
||||||
use File::Copy;
|
use File::Copy;
|
||||||
|
@ -121,11 +121,11 @@ sub crop
|
||||||
|
|
||||||
print "Image size: $iw $ih\n";
|
print "Image size: $iw $ih\n";
|
||||||
print "output size: $ow $oh\n";
|
print "output size: $ow $oh\n";
|
||||||
|
|
||||||
my ($x, $y);
|
my ($x, $y);
|
||||||
$x = int(rand($iw-$ow));
|
$x = int(rand($iw-$ow));
|
||||||
$y = int(rand($ih-$oh));
|
$y = int(rand($ih-$oh));
|
||||||
|
|
||||||
print "Cropping $image ${ow}x${oh}+${x}+${y}\n";
|
print "Cropping $image ${ow}x${oh}+${x}+${y}\n";
|
||||||
my $err = $im->Crop(geometry=>"${ow}x${oh}+${x}+${y}");
|
my $err = $im->Crop(geometry=>"${ow}x${oh}+${x}+${y}");
|
||||||
die "$err" if ($err);
|
die "$err" if ($err);
|
||||||
|
|
Loading…
Reference in New Issue