images | audio | feed | contact

pullingshots

a better image markdown

I am loving Markdown. But I am left wanting a lazier way of including images. I don't want to have to worry about creating thumbnails or different image sizes. I would like to be able to copy an image to my blog and from there simply give the image name and resolution, so that something like this:

 ![640](foobar)

would produce something like this:

 <a href='/link/to/original/or/detail/view'><img src='/path/to/640/foobar.jpg' /></a>

Obviously this requires a little bit of "Magick" in the background to find the path and ensure that the correct size thumb actually exists somewhere, but here's the code that I've come up with so far which accomplishes what I want (the "Magick" is hidden in the "images" function):

 while ($_->{content} =~ /\n\!\[(\d+)\]\((.+)\)/) {
   my @image = images($2, $1);
   my $html = $image[0]->{html} || "";
   $_->{content} =~ s/\n\!\[\Q$1\E\]\(\Q$2\E\)/$html/;
 }

Now this:

  ![300](the successful)

becomes this:

the successful

posted at 2011-06-10T06:05:52 by baerg