Skip to content

Instantly share code, notes, and snippets.

@usualoma
Created November 29, 2009 21:29
Show Gist options
  • Save usualoma/245076 to your computer and use it in GitHub Desktop.
Save usualoma/245076 to your computer and use it in GitHub Desktop.
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