Created
November 29, 2009 21:29
-
-
Save usualoma/245076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub _width_height { | |
my $src = shift; | |
my $content = get($src); | |
if (! $content) { | |
return ''; | |
} | |
my ($x, $y) = imgsize(\$content); | |
return ' width="' . $x . '" height="' . $y .'" '; | |
} | |
sub _insert_width_height { | |
my $text = shift; | |
my $padding = '(((?!width=)(?!height=)[^>])*)'; | |
my $src = '(src="([^"]*)")'; | |
$text =~ s/(<\s*img\s+)$padding$src$padding(\/?>)/ | |
$1 . $2 . $4 . _width_height($5) . $6 . $8 | |
/ige; | |
$text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment