oc-imageresizer-plugin icon indicating copy to clipboard operation
oc-imageresizer-plugin copied to clipboard

Max width or max height for images

Open ghost opened this issue 8 years ago • 6 comments

Hello,

I need to resize image that way :

  • It should never have a width more than 180px
  • It should never have a height more than 100px
  • Is should keep aspect ratio and not crop

I tested all provided modes but can't find a way to do that. I exclude "exact" and "crop" mode because of the third point, so there is "auto", "portrait" and "landscape"

The problem with landscape/portrait mode is that they resize picture just by looking the width/height value. So I can have picture of 2000x100px or 180x2000px.

I don't find any mode that can do what I need, could you please point me the right direction if a solution actually exist ?

here is my code :

image.jpg|media|resize(180, 100, { mode: '???' })

ghost avatar Apr 06 '17 14:04 ghost

Hey,

I would possibly use CSS to solve this, something along the lines of:

.image {
    height: 100px;
    width: 180px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center center;
}
<div class="image" style="background-image: url('{{ 'image.jpg' | media | resize(180, false, { mode: 'auto' }) }}');"></div>

matt-pawley avatar Apr 06 '17 14:04 matt-pawley

Hello,

Thank you for the answer.

Yes I have no problem to solve this using CSS.

The problem with CSS solution is that it load a bigger image and then, resize it. This is a bad practice that is penalized by tools like dareboost for example.

That's why I need a "pre-processing" solution. I think an additionnal mode to do that could be added to the plugin (will try to investigate, but I have no experience at all with git so I'm not sure to be able to make a pull request) as it's a quite common feature when you deal with something like logo list that can have very different formats and can't be cropped.

ghost avatar Apr 06 '17 14:04 ghost

Hi! Looking for exactly the same feature. Is there any progress in this question? I can make a contribution in coding the solution if there is no progress yet.

vdomah avatar Apr 19 '17 20:04 vdomah

@vdomah - Sorry, no progress from my end. I'm just in the process of moving house and without internet for a while so unlikely to be progressed any time soon. Feel free to submit a PR if you have the time.

matt-pawley avatar Apr 20 '17 08:04 matt-pawley

+1 This probably needs an update of the Resizer.php file of the octobercms/library. I have created a pull request in that project: https://github.com/octobercms/library/pull/334

yapsr avatar Jul 11 '18 10:07 yapsr

This plugin is being migrated to core (see #55), so we are trying to figure out what issues are still relevant to invite to reopen them in core.

Issues that will remain inactive in next 30 days will be closed.

matteotrubini avatar Aug 18 '20 10:08 matteotrubini