From ae25d16f496ce834cb8609101be520804d0d00f0 Mon Sep 17 00:00:00 2001 From: "C:\\Users\\eleksir\\AppData\\Roaming\\The Bat!" Date: Sat, 11 Nov 2017 21:25:45 +0300 Subject: [PATCH] img_wget.pl: if there is no Image::Magick in system do not use it in cygwin Image Magick looks not thread safe, at least it chokes when used in thread context, avoid using it --- img_wget.pl | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/img_wget.pl b/img_wget.pl index 36fba85..3dbafcb 100644 --- a/img_wget.pl +++ b/img_wget.pl @@ -3,7 +3,16 @@ use threads; use threads::shared; use URI::URL; -use Image::Magick; + +my $IMAGEMAGICK = undef; # use on demand +if ($^O ne 'cygwin') { # cygwin 2.882 64-bit hag broken Image::Magick + $IMAGEMAGICK = eval { + require Image::Magick; + import Image::Magick qw(ping); + return 1; + } +} + use Irssi qw (command_bind settings_get_bool settings_add_bool settings_get_str settings_add_str); @@ -100,19 +109,22 @@ sub dlfunc(@) { $url = urlencode($url); system($wgetpath, '--no-check-certificate', '-q', '-T', '20', '-O', $file, '-o', '/dev/null', $url); - if ($file =~ /(png|jpe?g|gif)$/i){ - my $im = Image::Magick->new(); - my $rename = 1; - my (undef, undef, undef, $format) = $im->Ping($file); + if (($^O ne 'cygwin') and defined($IMAGEMAGICK)) { + eval { + if ($file =~ /(png|jpe?g|gif)$/i){ + my $im = Image::Magick->new(); + my $rename = 1; + my (undef, undef, undef, $format) = $im->Ping($file); - if (defined($format)) { - $rename = 0 if (($format eq 'JPEG') and ($file =~ /jpe?g$/i)); - $rename = 0 if (($format eq 'GIF') and ($file =~ /gif$/i)); - $rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i)); - rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1); + if (defined($format)) { + $rename = 0 if (($format eq 'JPEG') and ($file =~ /jpe?g$/i)); + $rename = 0 if (($format eq 'GIF') and ($file =~ /gif$/i)); + $rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i)); + rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1); + } + } } } - return; }