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

Improve ImageEditor #50

Merged
merged 3 commits into from Mar 5, 2019
Merged

Improve ImageEditor #50

merged 3 commits into from Mar 5, 2019

Conversation

lydell
Copy link
Contributor

@lydell lydell commented Feb 18, 2019

It's very common to do img { width: 100%; height: auto; } to let
images fill out their container. And the image usually has more pixels
in width than the container has in CSS pixels, to look good on high
resolution screens.

Previously, when clicking an image to edit it djedi would immediately
replace the image with a preview – and set width: ...; height: ...
with inline style on it to the actual pixel sizes of the image. This
caused images to blow up in size and overflow their containers.

The reason this was done was to simulate cropping. It worked if images
were assumed to be displayed at their "natural" size, but that's rarely
the case.

This commit uses a canvas to simulate the cropping instead, and only
updates the src if the images on the page. This allows previewing the
cropping without breaking the page styling/layout.

When doing this, I found tons of little bugs and quirks. So the commit
ended up being a general refactor of the ImageEditor, making it
generally more stable and easier to understand.

I've also moved the Resize tab into the Image tab, since they are
closely related, and since the "Maintain aspect ratio" both affects the
width/height inputs as well as the crop tool. Another reason for doing
this is because I've hidden the "crop" input field, since it wasn't
editable and not useful.

@coveralls
Copy link

coveralls commented Feb 18, 2019

Coverage Status

Coverage remained the same at 97.35% when pulling 4da6584 on images into 79d35a7 on master.

It's very common to do `img { width: 100%; height: auto; }` to let
images fill out their container. And the image usually has more pixels
in width than the container has in CSS pixels, to look good on high
resolution screens.

Previously, when clicking an image to edit it djedi would immediately
replace the image with a preview – and set `width: ...; height: ...`
with inline style on it to the actual pixel sizes of the image. This
caused images to blow up in size and overflow their containers.

The reason this was done was to simulate cropping. It worked if images
were assumed to be displayed at their "natural" size, but that's rarely
the case.

This commit uses a canvas to simulate the cropping instead, and only
updates the `src` if the images on the page. This allows previewing the
cropping without breaking the page styling/layout.

When doing this, I found _tons_ of little bugs and quirks. So the commit
ended up being a general refactor of the ImageEditor, making it
generally more stable and easier to understand.

I've also moved the Resize tab into the Image tab, since they are
closely related, and since the "Maintain aspect ratio" both affects the
width/height inputs as well as the crop tool. Another reason for doing
this is because I've hidden the "crop" input field, since it wasn't
editable and not useful.
I’m not 100% sure this is the way to go, so the old behavior is left in
place and can be switched to from a variable.
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.

None yet

2 participants