Skip to content

Resize with fit#260

Open
dmzkrsk wants to merge 1 commit intoh2non:masterfrom
dmzkrsk:master
Open

Resize with fit#260
dmzkrsk wants to merge 1 commit intoh2non:masterfrom
dmzkrsk:master

Conversation

@dmzkrsk
Copy link
Copy Markdown

@dmzkrsk dmzkrsk commented Oct 8, 2018

Fixes #93, #257

Quality int
Compression int
Zoom int
Fit bool // Fit image into given dimensions
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed a new option to bypass settings Force=true in normalizeOperation later
I can't use Crop or Embed:

  • Crop will crop extra pixels
  • Embed will pad missing pixes with background


func normalizeOperation(o *Options, inWidth, inHeight int) {
if !o.Force && !o.Crop && !o.Embed && !o.Enlarge && o.Rotate == 0 && (o.Width > 0 || o.Height > 0) {
if !o.Force && !o.Fit && !o.Crop && !o.Embed && !o.Enlarge && o.Rotate == 0 && (o.Width > 0 || o.Height > 0) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I check Fit option to disable setting Force=true

// Fixed width and height
case o.Width > 0 && o.Height > 0:
factor = math.Min(xfactor, yfactor)
if o.Crop {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Crop option is set, then we should resize less and then crop
When no Crop option is set, we resize more, to fit the resulting rectangle

}
}

func TestResizeFit(t *testing.T) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test new feature

forceOptions := []bool{true, false}

for _, forceOpt := range forceOptions {
opts := Options{Width: 1000, Height: 20, Fit: true, Force: forceOpt}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also check, that Force=true results in old behavior

@dmzkrsk
Copy link
Copy Markdown
Author

dmzkrsk commented Oct 8, 2018

I added some notes in code review

@farcaller
Copy link
Copy Markdown

Any update on this?

@gnomeria
Copy link
Copy Markdown

Any update on this? How's the default resize behavior on bimg?

@ausaf007
Copy link
Copy Markdown

Is there any update on this feature? I need a functionality exactly same as this.

@suntong
Copy link
Copy Markdown

suntong commented Dec 2, 2023

Is there any update on this feature? I need a functionality exactly same as this.

See https://github.com/suntong/bimg/tree/dev

I.e., suntong@9dda52d

@suntong suntong mentioned this pull request Dec 2, 2023
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

Successfully merging this pull request may close these issues.

Using v1, resize operation should preserve aspect ratio or it should resize to the set dimension?

5 participants