Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andreyvolokitin opened this issue Oct 1, 2013 · 2 comments

Comments

@andreyvolokitin
Copy link

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?

@rantecki
Copy link
Contributor

rantecki commented Oct 2, 2013

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.

@andreyvolokitin
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants