use warnings use strict use Image Magick my file_name tmp xuj favicon

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use warnings;
use strict;
use Image::Magick;
my $file_name = "/tmp/xuj/favicon";
my $IM = Image::Magick->new();
$IM->Read($file_name.'.ico');
my $last_w = 0;
my $last_h = 0;
my $big_image;
for my $img (@$IM) {
my $width = $img->Get('width');
my $height = $img->Get('height');
if ($width == 16 && $height == 16) {
$big_image = $img;
last;
}
if ($width > $last_w || $height > $last_h) {
$big_image = $img;
$last_w = $width if ($width > $last_w);
$last_h = $width if ($height > $last_h);
}
}
if ($big_image->Get('width') != 16 || $big_image->Get('height') != 16) {
$big_image->Resize(width => 16, height => 16);
}
$big_image->Write(filename => $file_name.'xuj.png', background => 'none', alpha => 'on', 'flatten' => 1);