root/trunk/plagger/lib/Plagger/Util.pm

Revision 346 (checked in by miyagawa, 14 years ago)
  • Add new plugin Filter::ImageInfo? to fetch width & height from feed images. Fixes #80
  • Plagger::TT plugins
  • Plagger::Util::dumbnail function to resize images using img attributes
  • Add $feed->image to $entry->icon when copied to SmartFeed?
  • Fixed Frepa regular expression since they updated HTML
  • Updated Gmail template to fix big logo issue. Fixes #68
Line 
1 package Plagger::Util;
2 use strict;
3 our @ISA = qw(Exporter);
4 our @EXPORT_OK = qw( strip_html dumbnail );
5
6 use List::Util qw(min);
7 use HTML::Entities;
8
9 sub strip_html {
10     my $html = shift;
11     $html =~ s/<[^>]*>//g;
12     HTML::Entities::decode($html);
13 }
14
15 sub dumbnail {
16     my($img, $p) = @_;
17
18     if (!$img->{width} && !$img->{height}) {
19         return '';
20     }
21
22     if ($img->{width} <= $p->{width} && $img->{height} <= $p->{height}) {
23         return qq(width="$img->{width}" height="$img->{height}");
24     }
25
26     my $ratio_w = $p->{width}  / $img->{width};
27     my $ratio_h = $p->{height} / $img->{height};
28     my $ratio   = min($ratio_w, $ratio_h);
29
30     sprintf qq(width="%d" height="%d"), ($img->{width} * $ratio), ($img->{height} * $ratio);
31 }
32
33 1;
Note: See TracBrowser for help on using the browser.