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

Handle vectors #187

Merged
merged 4 commits into from
Oct 11, 2018
Merged

Handle vectors #187

merged 4 commits into from
Oct 11, 2018

Conversation

jakearchibald
Copy link
Collaborator

@jakearchibald jakearchibald commented Oct 10, 2018

DO NOT MERGE but please review (not based on master)

No longer fails when loading SVG.

Also, I made the resize preprocessor vector-aware, so it'll do the resizing in SVG if the source is SVG.

@jakearchibald jakearchibald changed the base branch from master to intro-component October 10, 2018 10:59
Copy link
Collaborator

@surma surma left a comment

Choose a reason for hiding this comment

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

Very cool. This is much less code than I anticipated.

@surma
Copy link
Collaborator

surma commented Oct 11, 2018

Hold on this, GitHub only showed me a subset of changes lol

Copy link
Collaborator

@surma surma left a comment

Choose a reason for hiding this comment

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

LGTM, one nit.

const endAspect = dw / dh;

if (endAspect > currentAspect) {
const newSh = dh / (dw / sw);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think with some shuffling, we can make the math a bit more “obvious”:
dh / (dw/sw) = sw * dh / dw = sw/endAspect

WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what's going on there, but it's definitely an invalid left-hand assignment. What am I missing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ohhh you mean change to sw / endAspect! I see now

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lol sorry. I am suggesting to use the expression on the very right and showing how I got there. This is not supposed to be JavaScript, just math :D My bad.

Copy link
Collaborator

Choose a reason for hiding this comment

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

... GitHub really needs to fix their stupid code-review UI to update when someone comments.

return { sw, sh: newSh, sx: 0, sy: newSy };
}

const newSw = dw / (dh / sh);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same trick here:

dw / (dh / sh) = sh * dw / dh = sh * endAspect

@surma
Copy link
Collaborator

surma commented Oct 11, 2018

One thing I just noticed (when testing the intro branch):

Vector-aware resize works great, but the source image doesn’t incorporate zoom. So if I “resize” the squoosh logo SVG at 4000x4000, the output image will appear sharper than the original. Do we wanna do something about that?

screen shot 2018-10-11 at 12 10 51 pm

@jakearchibald
Copy link
Collaborator Author

Ahh, so the idea would be that the SVG stays sharp when scaled, but the compressed version is pixels? I can take a swing at that.

@surma
Copy link
Collaborator

surma commented Oct 11, 2018

Yeah, I guess we should prevent rasterizing at every zoom interaction, but maybe we can rasterize at 200% once zoom is above 100%, rasterize at 400% once zoom is above 200% or something along those lines?

@jakearchibald
Copy link
Collaborator Author

I think we get it for free if I add the <img> to the output rather than a <canvas>. Zooming would be slower though.

@surma
Copy link
Collaborator

surma commented Oct 11, 2018

Happy to leave this as a stretch goal. (aka punt to a separate, future PR)

@jakearchibald
Copy link
Collaborator Author

Filed #190 for the sharpness thing. I agree it's worth doing.

I also made the resizer vector-aware, so you can resize the image larger & stay sharp.
@jakearchibald jakearchibald changed the base branch from intro-component to master October 11, 2018 13:14
@jakearchibald jakearchibald merged commit d2f60ba into master Oct 11, 2018
@jakearchibald jakearchibald deleted the handle-vectors branch October 11, 2018 13:16
alisaitbilgi pushed a commit to alisaitbilgi/squoosh that referenced this pull request Feb 19, 2019
* Allow loading SVG. Fixes GoogleChromeLabs#138.

I also made the resizer vector-aware, so you can resize the image larger & stay sharp.

* Handling SVG without width/height set.

* Simplifying maths

* Doh, case sensitive
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.

2 participants