Skip to content

Reduce the size of the images within the QR of the invoice #641 - #660

Merged
grunch merged 5 commits into
lnp2pBot:mainfrom
Luquitasjeffrey:ticket641
Jun 19, 2025
Merged

Reduce the size of the images within the QR of the invoice #641#660
grunch merged 5 commits into
lnp2pBot:mainfrom
Luquitasjeffrey:ticket641

Conversation

@Luquitasjeffrey

@Luquitasjeffrey Luquitasjeffrey commented May 27, 2025

Copy link
Copy Markdown
Collaborator

To reduce the size of the images I added a new configuration environment variable that can set the size of an image relative to the size of the qr image, for instance if IMAGE_TO_QR_RATIO is set to 0.2 that means that imageWidth = 0.2*qrWidth

Summary by CodeRabbit

  • New Features

    • Added support for customizing the size ratio of the center image relative to the QR code using a new environment variable.
  • Chores

    • Updated sample environment file to include the new configuration option.

@coderabbitai

coderabbitai Bot commented May 27, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new environment variable, IMAGE_TO_QR_RATIO, was introduced in the .env-sample file to control the size ratio of an image embedded within a QR code. In the utility code, the image size calculation now uses this environment variable, with the import statements updated to ES module syntax.

Changes

Files Change Summary
.env-sample Added IMAGE_TO_QR_RATIO environment variable sample.
util/index.ts Switched imports to ES module syntax; image-to-QR size ratio now configurable via environment.

Poem

🐇
A ratio for images, now set with great care,
In the heart of the QR, your logo can flare.
With imports made modern, and configs anew,
The code hops ahead—so much it can do!
Cheers to the tweaks, both subtle and bright,
QR bunnies rejoice, for the ratio is right!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-18T22_58_47_515Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0fe3cb and 6fd2135.

📒 Files selected for processing (1)
  • util/index.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • util/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: ci_to_main
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
util/index.ts (1)

17-18: Address import syntax inconsistency.

The conversion to ES module imports is good, but the file still mixes ES modules with CommonJS requires (lines 13-15). This creates inconsistency in the codebase.

Consider converting all imports to ES modules for consistency:

-const fs = require('fs').promises;
-const path = require('path');
-const { I18n } = require('@grammyjs/i18n');
+import { promises as fs } from 'fs';
+import path from 'path';
+import { I18n } from '@grammyjs/i18n';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6592b1b and dd29264.

📒 Files selected for processing (2)
  • .env-sample (1 hunks)
  • util/index.ts (3 hunks)
🔇 Additional comments (1)
.env-sample (1)

85-86: LGTM! Well-documented configuration addition.

The new environment variable is clearly documented and the default value of 0.2 (20% ratio) aligns perfectly with the PR objective to reduce image size within QR codes.

Comment thread util/index.ts Outdated
@grunch
grunch requested a review from Catrya June 4, 2025 12:51
Comment thread util/index.ts Outdated

// Validate ratio is a valid number between 0.1 and 0.5
if (isNaN(imageToQrRatio) || imageToQrRatio < 0.1 || imageToQrRatio > 0.5) {
logger.warn(`Invalid IMAGE_TO_QR_RATIO value: ${rawRatio}, using default 0.2`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @Luquitasjeffrey You're using logger.warn(...), but since the project uses winston.config.syslog.levels, the correct method is logger.warning(...).
please fix that because as it is now, if the ratio is out of bounds, the QR with the image isn’t generated and this is show in the logs

[2025-06-04T11:38:29.984-06:00] error: logger_1.logger.warn is not a function TypeError: logger_1.logger.warn is not a function
    at /home/catry/bot/dist/util/index.js:775:37
    at step (/home/catry/bot/dist/util/index.js:33:23)
    at Object.next (/home/catry/bot/dist/util/index.js:14:53)
    at fulfilled (/home/catry/bot/dist/util/index.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@Catrya

Catrya commented Jun 13, 2025

Copy link
Copy Markdown
Member

Hi @Luquitasjeffrey how are you progressing with this PR? Let me know if you need any help

@Catrya Catrya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tACK good job @Luquitasjeffrey

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

utACK

@grunch
grunch merged commit 41323eb into lnp2pBot:main Jun 19, 2025
5 checks passed
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.

3 participants