Smileyt / python-markdown2

Automatically exported from code.google.com/p/python-markdown2
Other
0 stars 0 forks source link

"img sizes" patch from James Eagan #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
James wrote:

[A patch] to automatically calculate image sizes and insert
them into the generated HTML (see the attached patch, made off the svn
trunk).  Whenever it's about to write an HTML <img> tag, it checks if
the url is relative or absolute.  If it's absolute, it loads the URL
and tries to calculate the dimensions of the image.  If it's relative,
it checks to see if a file exists on the local filesystem relative to
the current working directory and uses that for the size.  Whenever it
can't find the size, it omits the width and height attributes, falling
back to the existing behavior.

This patch uses two approaches for calculating image sizes.  First, it
tries to use Cocoa's NSImage on the Mac.  Of course, this will fail on
non-Macs, so it then falls back to trying to use the Python Imaging
Library (PIL).  (I don't use PIL first, since it is sometimes compiled
without PNG or JPEG support.)  Finally, if none of those libraries is
available, it just reverts to the current behavior, omitting the size
attributes.

Please feel free to use this patch as you see fit.  I have not written
any test cases for it, nor have I given it any sort of a rigorous
quality assurance.  It works for me on my machine with my input files,
but I haven't tried it under any other setup.

Original issue reported on code.google.com by tre...@gmail.com on 28 Nov 2007 at 4:51

Attachments:

GoogleCodeExporter commented 8 years ago
Not sure about having text-to-html conversion do HTTP GETs. 
My (limited) understanding is that img width/height aren't *that* critical: 
they only
have effect while the browser loads the page, before the image is loaded. Hrm.

Ideally I think I'd want to have some kind of extensions mechanism a la
python-markdown(1) for this but can possibly put this in via "extras".

Original comment by tre...@gmail.com on 28 Nov 2007 at 5:19