docpad-plugin-thumbnails icon indicating copy to clipboard operation
docpad-plugin-thumbnails copied to clipboard

Ability to set 'width' and 'height' <img /> attributes automatically

Open andreyvolokitin opened this issue 11 years ago • 2 comments

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?

andreyvolokitin avatar Oct 01 '13 13:10 andreyvolokitin

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.

rantecki avatar Oct 02 '13 01:10 rantecki

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...

andreyvolokitin avatar Oct 03 '13 10:10 andreyvolokitin