libvips / libvips/libvips

vips_thumbnail: Prefer width over height or vice versa

Open
#709 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.7k
Forks
797
Avg merge
3d 6h
Merged PRs (30d)
15

Description

I like to see a (optional) prefer option in vips_thumbnail which can be set to a new enum (let's call it VIPS_PREFER_WIDTH or VIPS_PREFER_HEIGHT for example).

Use case scenario:
To prevent reduction or enlargement in the horizontal axis, I'm setting the target resize width to VIPS_MAX_COORD (which is currently 10000000), when a user only have specified a fixed height. I'm doing vice versa for the target resize height (so setting it to VIPS_MAX_COORD when a fixed width is specified). This feels somewhat hackish.

Example which currently fails due to reduction in the vertical axis (the dimensions of the input JPEG-file are 1600x622):
https://gist.github.com/kleisauke/8e090b4f83679cd536cd3bc7aebe60a2

thumbnail width = 499
expected width = 500
thumbnail height = 194
expected height = 194

This is fixable if we change the script to this:
https://gist.github.com/kleisauke/a7df1817fa7ed8f01a627a7eccd342c4

thumbnail width = 500
expected width = 500
thumbnail height = 194
expected height = 194

When a prefer option is in vips_thumbnail we can do:
https://gist.github.com/kleisauke/1dc424dfdf1b2b65192be4189a4c6364

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the vips_thumbnail entry point and reproduce the linked JPEG example to understand the current dimension selection. Review the proposed prefer option and enum behavior in the linked examples; done means fixed-width and fixed-height requests choose the preferred axis without the current one-pixel reduction or enlargement.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
api, computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.