docpad-plugin-thumbnails
docpad-plugin-thumbnails copied to clipboard
Ability to set 'width' and 'height' <img /> attributes automatically
Is it possible to make a thumbnail and set its dimensions in html automatically? Or get and set dimensions of already existing image? gm library have getter for image size, and in theory we could use any operation supported by gm library, so it looks like no problem with setting dimensions for existing images. But how we set image size of thumbnail that not yet exist?
I don't think it's possible to do this for a standard thumbnail unless you knew the dimensions of the source image and applied the same scaling rules as the thumbnail algorithm. Cropscale would be easier as the dimensions are guaranteed to be the target dimensions (unless of course the source image is smaller than the crop size).
Depending on your thumbnailing algorithm, at least one of width or height will generally be known, and you can add the known quantity to the HTML.
So there is no way to just get size of existing image? I have made this target in docpad.coffee according to this:
plugins:
thumbnails:
targets:
'size': (img, args) ->
return img.size((err, value) ->)
and in my templates I have made this:
<%= @getThumbnail('path/to/the/img.jpeg', 'size') %>
But it just returning path to the thumbnail...