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

Proposal: Add an option to make device scale factor flexible, in addition to the existing --retina argument #136

Closed
nielthiart opened this issue Dec 18, 2023 · 1 comment

Comments

@nielthiart
Copy link
Contributor

nielthiart commented Dec 18, 2023

The --retina argument is convenient to set a device scale factor of 2, but for my use case I needed a variety of scale factors to match other displays.

Ref: #133

For example, Google Pixel 6 has a scale factor of 2.625. Some devices go up to 4.

My proposal is to add an additional argument, --scale-factor, that takes a float as argument, and is None by default.

To avoid confusion when using --retina and --scale-factor simultaneously, we could treat them as mutually exclusive and raise a helpful error. We can also check that the scale factor is positive.

A reusable function that validates and normalises the device scale factor provides the opportunity to validate other scale-factor-altering arguments in the future, such as the --device argument proposed in #129.

nielthiart added a commit to nielthiart/shot-scraper that referenced this issue Dec 18, 2023
This commit adds tests for the `--scale-factor` argument.

Ref: simonw#136
simonw pushed a commit that referenced this issue Feb 5, 2024
* Add a scale factor option

Adds the `--scale-factor` option.

The `--scale-factor` option allows users to specify a specific device scale factor as a float.

This is useful for testing specific high-definition displays. For example, the Google Pixel 6 has a pixel ratio of 2.625. Some modern phones have pixel ratios of 4.

The existing `--retina` option is a specific case of the new `--scale-factor` option.

The commit also includes a validation to prevent conflicts when using the `--scale-factor` and `--retina` options together.

* Add scale factor tests

This commit adds tests for the `--scale-factor` argument.

Ref: #136
@simonw
Copy link
Owner

simonw commented Feb 5, 2024

From a successful GitHub Actions run:

simonwillison-retina:

simonwillison-retina

simonwillison-scale-factor-pixel-six:

simonwillison-scale-factor-pixel-six

# --retina
shot-scraper https://simonwillison.net/ -h 400 -w 800 \
-o examples/simonwillison-retina.png --retina
# --scale-factor
shot-scraper https://simonwillison.net/ -h 915 -w 412 \
-o examples/simonwillison-scale-factor-pixel-six.png --scale-factor 2.625

@simonw simonw closed this as completed Feb 5, 2024
simonw added a commit that referenced this issue Feb 5, 2024
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