12:46 アイコン(サムネイル)を作るモジュール
ImageMagickでAnimated GIFのサムネイルをきれいにつくる方法 : blog.nomadscafe.jpのオマケ
package Iconizer; use strict; use warnings; use base qw/Class::Accessor::Fast/; use IPC::Run; use File::Copy; __PACKAGE__->mk_accessors( qw/input size output width height frames/ ); sub do_identify { my $self = shift; my %identify; my $h = IPC::Run::start( [ '/usr/bin/identify', $self->input ], map { \$identify{$_} } qw/in out error/ ); my $identify = $h->finish; die "identify failed: $identify{error}\n" unless $identify; my @identify = split /\n/, $identify{out}; $self->frames(scalar @identify); if ( $identify[0] =~ / \d+x\d+ (\d+)x(\d+)\+\d\+\d/ ) { $self->width($1); $self->height($2); } elsif ( $identify[0] =~ / (\d+)x(\d+) / ) { $self->width($1); $self->height($2); } else { die "cannot identify file\n"; } } sub do_convert { my $self = shift; my $resize_height = $self->size; my $resize_width = $self->size; if ( $self->width > $self->height ) { $resize_width = int ($self->width * $self->size)/$self->height; } else { $resize_height = int ($self->height * $self->size)/$self->width; } $resize_width ||= 1; $resize_height ||= 1; my $top=0; my $left=0; if ( $resize_width > $resize_height ) { $left = int ($resize_width - $self->size)/2; } else { $top = int ($resize_height - $self->size)/2; } my %convert; my $h = IPC::Run::start( [ '/usr/bin/convert', '-size', $self->width . "x" . $self->height, $self->input, '-coalesce', '-resize', $resize_width . "x" . $resize_height, '-sharpen', '1', '-crop', sprintf("%sx%s+%s+%s", $self->size,$self->size,$left,$top), '+repage', '-deconstruct', $self->output ], map { \$convert{$_} } qw/in out error/ ); my $convert = $h->finish; die "convert failed: $convert{error}\n" unless $convert; my $ext; my $name; if ( $self->output =~ /\.([^.]+)$/ ) { $name = $`; $ext = $1; } if ( -f "$name-0.$ext" ) { File::Copy::copy("$name-0.$ext", $self->output); for(my $i=0;$i<$self->frames;$i++){ unlink "$name-$i.$ext"; } } } package main; my $icon = Iconizer->new({ input => "input.gif", output => "output.gif", size => 32 }) $icon->do_identify; $icon->do_convert;