root/lang/perl/plagger/lib/Plagger/Plugin/Filter/EnclosureImageSize.pm

Revision 560, 2.5 kB (checked in by mayuki, 11 months ago)

lang/perl/plagger: import Filter::Diff, Filter::EnclosureImageSize?, Filter::JugemEmoji?

Line 
1# $Id: EnclosureImageSize.pm 113 2007-08-27 15:22:40Z mayuki $
2package Plagger::Plugin::Filter::EnclosureImageSize;
3use strict;
4use base qw( Plagger::Plugin );
5
6use Image::Size;
7
8sub register {
9    my($self, $context) = @_;
10
11    $context->register_hook(
12        $self,
13        'update.entry.fixup' => \&filter
14    );
15}
16
17sub filter {
18    my($self, $context, $args) = @_;
19
20    my $e = $args->{entry};
21
22    if ($e->has_enclosure) {
23        for my $enclosure (grep { -e $_->local_path } $e->enclosures) {
24            my ($width, $height, $type, $drop);
25            eval { ($width, $height, $type) = imgsize($enclosure->local_path); };
26            next unless $width && $height;
27
28            $context->log(debug => "Image Size: $width x $height, Type: $type");
29            if ($self->conf->{min_height} && $self->conf->{min_height} > $height) {
30                $drop = 1;
31                $context->log(debug => "MinHeight: " . $self->conf->{min_height} . " px");
32            }
33            if ($self->conf->{min_width} && $self->conf->{min_width} > $width) {
34                $drop = 1;
35                $context->log(debug => "MinWidth: " . $self->conf->{min_width} . " px");
36            }
37            if ($self->conf->{max_height} && $self->conf->{max_height} < $height) {
38                $drop = 1;
39                $context->log(debug => "MaxHeight: " . $self->conf->{max_height} . " px");
40            }
41            if ($self->conf->{max_width} && $self->conf->{max_width} < $width) {
42                $drop = 1;
43                $context->log(debug => "MaxWidth: " . $self->conf->{max_width} . " px");
44            }
45            if ($self->conf->{type} && $type =~ /$self->conf->{type}/i) {
46                $drop = 1;
47                $context->log(debug => "Type: " . $self->conf->{type});
48            }
49
50            if ($drop) {
51                $context->log(info => "Drop enclosure/file " . $enclosure->local_path);
52
53                $e->{enclosures} = [ grep { $_->local_path ne $enclosure->local_path } $e->enclosures ];
54                unlink $enclosure->local_path
55                    or $context->log(error => "can't remove file '".$enclosure->local_path."'");
56            }
57        }
58    }
59}
60
611;
62__END__
63
64=head1 NAME
65
66Plagger::Plugin::Filter::EnclosureImageSize -
67
68=head1 SYNOPSIS
69
70- module: Filter::FindEnclosures
71- module: Filter::FetchEnclosure
72- module: Filter::EnclosureImageSize
73  config:
74    min_height: 100
75    min_width: 100
76
77=head1 DESCRIPTION
78
79[ato de kaku]
80
81=head1 CONFIG
82
83=head1 AUTHOR
84
85Mayuki Sawatari
86
87=head1 SEE ALSO
88
89L<Plagger>, L<Plagger::Plugin::Filter::FetchEnclosure>
90
91=cut
Note: See TracBrowser for help on using the browser.