question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong aspectRatio displayed on mobile (Android & iOS)

See original GitHub issue

Describe the bug

I want to create an fullscreen scanner, so I setted the aspectRatio = window.innerWidth / window.innerHeight (the result on iphone 8 is 0.6843065693430657). But the video was rendered with a wrong aspect ratio (landscape instead of portrait). Additionally, It worked great on MacOs’s Chrome and was not stable on MacOs’s Safari (sometime correct, sometime wrong).

To Reproduce

         this.html5QrCode = new Html5Qrcode('qr-reader')

          const camera = { facingMode: 'environment' }
          const qrBoxSize = 250
          const width = window.innerWidth
          const height = window.innerHeight
          const aspectRatio = width / height
          const config = {
            fps: 20, // frame per seconds for qr code scanning
            aspectRatio,
            qrbox: { width: qrBoxSize, height: qrBoxSize },
          }

          await this.html5QrCode.start(
            camera,
            config,
            (decodedText, decodedResult) => this.onScanSuccess(decodedText, decodedResult),
            (error) => this.onScanFailure(error),
          )

Expected behavior

The camera’s video should be display with correct aspect ratio (fullscreen)

Screenshots

8d2a45f02280efdeb691

Desktop (please complete the following information):

  • OS: macOS
  • Browser: safari + chrome on iPhone, safari on macOS.
  • Version: 96

Smartphone (please complete the following information):

  • Device: iphone 6, Xiaomi Redmi
  • OS: iOS 15.1
  • Browser: safari, chrome
  • Version: latest

Additional context Add any other context about the problem here.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
bahung1221commented, Feb 22, 2022

You can try the hack below, which worked perfectly for me.

          const width = window.innerWidth
          const height = window.innerHeight
          const aspectRatio = width / height
          const reverseAspectRatio = height / width

          const mobileAspectRatio = reverseAspectRatio > 1.5
            ? reverseAspectRatio + (reverseAspectRatio * 12 / 100)
            : reverseAspectRatio

          const config = {
            fps: 20, // frame per seconds for qr code scanning
            qrbox: { width: qrBoxSize, height: qrBoxSize },
            videoConstraints: {
              facingMode: 'environment',
              aspectRatio: width < 600
                ? mobileAspectRatio
                : aspectRatio,
            },
          }
0reactions
kunambicommented, Mar 30, 2022

@bahung1221

qrBoxSize

Where is this variable set?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Change the Screen Resolution on Your Android
1. Open your Android's {"smallUrl":"https:\/\/www.wikihow.com\/images\/e\/ed\/Android7settingsapp.png","bigUrl":"\/images\/thumb\/e\/ed\/Android7settingsapp ... 2. Tap Display. It's next to an icon that resembles a sun in the Settings menu. If you...
Read more >
Wrong aspect ratio in apps - Apple Community
Wrong aspect ratio in apps. Some apps, like YouTube, are cut by the black bar on top of my iPhone screen. How can...
Read more >
How to change the aspect ratio of a video on an Android phone
There are two ways. The first is by changing the aspect ratio, and then adjusting the width and height of the video; the...
Read more >
Is it possible to change iPhone X, iPhone XS, XS Max, XR, to ...
No, it is not possible to generally change the aspect ratio of the screen for any third party app. You'll have to contact...
Read more >
Declare restricted screen support - Android Developers
We recommend a ratio of 2.4 (12:5). Your app will be letterboxed when it runs on a device with an aspect ratio greater...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found