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

feat: improve save as PNG, SVG and copy to clipboard #3252

Merged
merged 33 commits into from
Oct 9, 2024

Conversation

hamed-musallam
Copy link
Member

@hamed-musallam hamed-musallam commented Sep 27, 2024

Browsers have limits on the maximum size of a canvas, These limits differ by browser, Chrome's maximum canvas size is 16,384 x 16,384 pixels.

Chrome:
Maximum height/width: 32,767 pixels
Maximum area: 268,435,456 pixels ( 16,384 x 16,384)

Firefox:
Maximum height/width: 32,767 pixels
Maximum area: 472,907,776 pixels ( 22,528 x 20,992)

@hamed-musallam hamed-musallam linked an issue Sep 27, 2024 that may be closed by this pull request
Copy link

cloudflare-workers-and-pages bot commented Sep 30, 2024

Deploying nmrium with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0d7c476
Status: ✅  Deploy successful!
Preview URL: https://b6c1ab5c.nmrium.pages.dev
Branch Preview URL: https://improve-save-as-image.nmrium.pages.dev

View logs

@hamed-musallam hamed-musallam force-pushed the improve-save-as-image branch 2 times, most recently from 2fa4955 to 76a9a00 Compare September 30, 2024 11:35
@hamed-musallam hamed-musallam marked this pull request as ready for review September 30, 2024 12:25
@hamed-musallam hamed-musallam changed the title feat: Improve export spectra as png and svg feat: improve save as PNG, SVG and copy to clipboard Sep 30, 2024
@lpatiny
Copy link
Member

lpatiny commented Oct 7, 2024

Default in 'cm'.

There should be a simple mode in which the user select a size (default to A5) and a resolution (default to 300 DPI). From those values we can calculate the number of HORIZONTAL pixels.

A5 is 8.3 x 5.8 this means 2490 x 1740 px.

If we have for example on the screen 1027 x 853 we need to call the method:

function createObjectURL(blob: Blob, options: CreateObjectURLOptions) {
  const { resolution, width, height } = options;

  const canvas = document.createElement('canvas');
  const context = canvas.getContext('2d');

We need a new SVG with the correct ratio. We don't change the width but we change only the height. New height = 1740 / 2490 * 1027 = 718 px. So we create the SVG with 1027 x 853.

Now we need to calculate the scale factor:

Scale factor: 2490 / 1027 = 2.42

image

@lpatiny
Copy link
Member

lpatiny commented Oct 7, 2024

Save in cm and reload is a mess

image

Do not display decimals for px and it should be written @300 and not @cm dpi

image

@hamed-musallam hamed-musallam force-pushed the improve-save-as-image branch 3 times, most recently from 57b70e9 to 934c4c8 Compare October 8, 2024 10:58
@lpatiny
Copy link
Member

lpatiny commented Oct 8, 2024

The functionality looks ok to me but for now just hide the toggle Basic / Advanced. We will keep only Basic and wait if somebody really needs the advanced mode.

image

@lpatiny
Copy link
Member

lpatiny commented Oct 8, 2024

Could you still add shortcuts so that 'ENTER' validates the dialog and 'ESC' cancel it ?

@hamed-musallam hamed-musallam force-pushed the improve-save-as-image branch 2 times, most recently from 69ab531 to f419002 Compare October 8, 2024 17:45
@hamed-musallam hamed-musallam enabled auto-merge (squash) October 9, 2024 07:10
@hamed-musallam hamed-musallam merged commit 683eb63 into main Oct 9, 2024
12 checks passed
@hamed-musallam hamed-musallam deleted the improve-save-as-image branch October 9, 2024 07:13
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.

Copy / Save as PNG - width / height
2 participants