andismith / grunt-responsive-images

Produce images at different sizes for responsive websites.
http://www.andismith.com/grunt-responsive-images/
MIT License
718 stars 96 forks source link

Limit width and height to even numbers #108

Closed jackocnr closed 8 years ago

jackocnr commented 8 years ago

Hi there, thanks for a brilliant tool! I just updated to v0.1.7 and love the perf improvement!

In my project (intl-tel-input), I need to generate images with even pixel values for the width and height. I'm currently doing this in a very hacky way in a second step using evenizer. Is there any way to tell the underlying image processing tool (I'm currently using ImageMagick but would be happy to change) to do this?

Thanks very much for your help, and such a great project!

njanmelbin commented 8 years ago

Hey, set the width and height and aspectRatio to false and image will be cropped.

jackocnr commented 8 years ago

Hi, thanks for your response. Unfortunately I need to keep the aspect ratio, so that wont work.

gooneraki commented 8 years ago

@jackocnr How can you change the width and height without changing the aspect ratio? Im an amateur btw so maybe Im missing something

jackocnr commented 8 years ago

My understanding is that when you set width and height, those are the maximum values, so it maintains aspect ratio and outputs an image with the largest dimensions that fit within that max width and max height. So in my case, I have it set to width: 40 and height: 30, and I get images out that are 40x20, 36x30, 40x28, 30x30 etc. The problem for me is when I get one that has an odd dimension like 40x21.

gooneraki commented 8 years ago

Well, to transform the image into a square image you either need to crop it as @njanmelbin suggested or stretch it (which will look awful).

Since you want even number of pixels in height and width, why did you set it to width: 40 and height: 30?

jackocnr commented 8 years ago

I don't want a square image! I think there has been a misunderstanding - I don't want the width and the height to be the same as each other - I want them both to be even numbers (ie. a multiple of 2). Sorry for the misunderstanding! I have updated the title of this issue to be more clear.

FYI I'm dealing with flags, most of which are close to 4x3 ratio, which I need to preserve. Thanks.

gooneraki commented 8 years ago

Hm. I don't think there is a specific option to set the dimensions to be an even number.

I can't think that being useful. :) Is it that bad that the picture is 40x21 and not 40x20? :)

Good luck finding a solution.

jackocnr commented 8 years ago

The reason I need this is to generate retina images (@2x), then from those images I can safely half the size to get regular images (@1x). But you can only safely half the size if all the dimensions are even numbers.

andismith commented 8 years ago

Hi,

Thanks for the issue report.

I'm not sure how we would make 'even numbers' a feature, it's beyond the scope of this plugin.

This plugin's features and functionality have already escalated far beyond what was already imagined and if we add an even feature, we'd have to add an odd feature, and then a feature for ever ten units, and then five. It's just never ending for what is essentially an edge case.

I'm going to close this issue, but if people feel strongly about this feature, please add a thumbs up to the original post and I'll re-address should demand be high enough.

Thanks, Andi