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(web): image editor - panel and cropping #11074

Merged
merged 61 commits into from
Aug 14, 2024
Merged

Conversation

ilyaChuk
Copy link
Contributor

@ilyaChuk ilyaChuk commented Jul 13, 2024

Another attempt to create a photo editor. I hope it's the final one. #10883

image
Video

I made a sidebar with tools. so far, there is a cropping and adjustment tool (placeholder).
Cropping works - you can freely choose the size or use the preset.
I checked on different pictures: horizontal, square, vertical. I didn't notice any problems.
Only the desktop version works. I haven't adapted it to mobile screens.
This is only a web interface, there is no server part of this functionality yet.

TODO:

  • [ ] Adaptation to mobile screens.
  • [x] Canvas performance optimization.

@ilyaChuk ilyaChuk changed the title Web image editor: panel and cropping feat: web image editor - panel and cropping Jul 13, 2024
@ilyaChuk ilyaChuk changed the title feat: web image editor - panel and cropping feat(web): image editor - panel and cropping Jul 13, 2024
@opbod
Copy link
Contributor

opbod commented Jul 15, 2024

Related: #10989 (Mobile); #3271 (Web); #9575 (Web)

@ilyaChuk
Copy link
Contributor Author

I feel like I'm ready. The cropping interface is ready.
image
There is a editor tools sidebar on desktop screens. So far, there's only cropping, but she's ready to work with an array of tools.
Since last time, I added a "save" button. It is active only when changes have been made in the editor. So far, clicking on it does nothing except close the editor and the panel.
I've double-checked everything several times, different aspect ratios of the images, it works stably for me.
This is the first time I have had such an experience, but I tried to make the code convenient for other developers as well.
video

@ilyaChuk ilyaChuk marked this pull request as ready for review July 29, 2024 02:06
@opbod
Copy link
Contributor

opbod commented Jul 29, 2024

#10989 just got accepted into main few hours ago, mobile-only.
@martyfuhry does this web-only image editor PR conflict with or enrich the overall setup?

@bo0tzz bo0tzz requested a review from alextran1502 July 29, 2024 08:32
Copy link
Contributor

@michelheusschen michelheusschen left a comment

Choose a reason for hiding this comment

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

First off, a big thank you for the PR. Having an editor would be a great addition to Immich!

web/src/lib/components/asset-viewer/asset-viewer.svelte Outdated Show resolved Hide resolved
web/src/lib/components/asset-viewer/asset-viewer.svelte Outdated Show resolved Hide resolved
let animationFrame: ReturnType<typeof requestAnimationFrame>;
let canvasCursor: string;
const getAssetUrl = (id: string, checksum: string) => {
return `http://localhost:2283/api/assets/${id}/original?c=${checksum}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the original asset can't be displayed by the browser? Also this URL should be changed

Copy link
Contributor

Choose a reason for hiding this comment

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

This is only partially resolved. There is still the possibility that a browser can't display the original asset. This will also be an issue for videos, live photos and panoramas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we even allow the editor to be opened for live photos, panoramas, and gifs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now it makes sense to disable the editor for these types of assets. If there are tools added in the future that can be used for more asset types (like rotate), we can always reconsider this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@michelheusschen

There is still the possibility that a browser can't display the original asset

And then what to show? now there is an error message when opening the editor and an error loading the image. An error message, a black editor screen, and a toolbar on the right.
Should I close the editor automatically in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now it makes sense to disable the editor for these types of assets

done

Comment on lines 61 to 62
// Vertical lines
const thirdWidth = crop.width / 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a huge fan of the grid lines personally, maybe only show them while changing the crop area?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the lines visible only when the cropping rectangle is changed. But then, when the cropping rectangle is the same size as the image, it is poorly visible
image
I can't imagine how to solve this in a simple way. I added small circles on the corners for more visibility.
image
But maybe as long as the rectangle is the same size as the image, draw these lines?
Although if this is just a problem for me, then everything is ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think this is better. The dots only seem to get cut off at the edges, maybe there's a way to extend them? I also noticed that cropping immediately stops when the cursor leaves the canvas. Can we allow cropping to continue when that happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will require some reworking, but I will try

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't easy, but it's done. video

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing that might be worth looking into down the road is using sharp to do the actual cropping on the original asset. So always show the crop tool on the jpeg/webp thumbnail and use it to get the cropping coordinates, but when send those to the server which can actually perform the operation. I believe using sharp it would be possible to keep the metadata, etc.

web/src/lib/stores/preferences.store.ts Outdated Show resolved Hide resolved
@ilyaChuk
Copy link
Contributor Author

@opbod

does this web-only image editor PR conflict with or enrich the overall setup?

We try to work together by discussing our roles. But the difference so far is that I cannot rotate the image, and it is not saved.

@ilyaChuk
Copy link
Contributor Author

ilyaChuk commented Aug 10, 2024

Feels ready 😴
no, I found a problem with very long or very wide images. It's not easy to fix. in the morning

@ilyaChuk
Copy link
Contributor Author

Ok, now I don't see any errors. Yet

@ilyaChuk
Copy link
Contributor Author

but I still don't understand the error I'm getting here https://github.com/immich-app/immich/actions/runs/10328229151/job/28597174488

@alextran1502 alextran1502 enabled auto-merge (squash) August 14, 2024 13:42
auto-merge was automatically disabled August 14, 2024 14:09

Head branch was pushed to by a user without write access

@alextran1502 alextran1502 merged commit 7f7fec2 into immich-app:main Aug 14, 2024
22 checks passed
@eygraber
Copy link
Contributor

I saw this in the release notes, but it doesn't look like it is available. Is it disabled, or hidden?

@ilyaChuk
Copy link
Contributor Author

@eygraber Yeah, it's hidden for now. I think we'll launch it when the server side is ready.

Yuvi-raj-P pushed a commit to Yuvi-raj-P/immich that referenced this pull request Aug 19, 2024
* cropping, panel

* fix presets

* types

* prettier

* fix lint

* fix aspect ratio, performance optimization

* improved tool selection, removed placeholder

* fix the mouse's exit from canvas

* fix error

* the "save" button and change tracking

* lint, format

* the mini functionality of the save button

* fix aspect ratio

* hide editor button on mobiles

* strict equality

Co-authored-by: Michel Heusschen <[email protected]>

* Use the dollar sign syntax for stores inside components

* unobtrusive grid lines, circles at the corners

* more correct image load, handleError

* more strict equality

* fix styles. unused and tailwind

Co-Authored-By: Michel Heusschen <[email protected]>

* dont store isShowEditor

* if showEditor - hide navbar & shortcuts

* crop-canvas decomposition (danger)

I could have accidentally broken something.. but I checked the work and it seems ok.

* fix lint

* fix ts

* callback function as props

* correctly disabling shortcuts

* convenient canvas borders

• you can use the mouse to go beyond the boundaries and freely change the crop.
• the circles on the corners of the canvas are not cut off.

* -the editor button for video files, -save button

* hide editor btn if panoramic || gif || live

* corners instead of circles (preview), fix lint&format

* confirm close editor without save

* vertical aspect ratios

* recovery after merge. editor's closing shortcut

* fix format

* move from canvas to html elements

* fix changes detections

* rotation

* hide detail panel if showing editor

* fix aspect ratios near min size

* fix crop area when changing image size when rotate

* fix of fix

* better layout - grouping

https://github.com/user-attachments/assets/48f15172-9666-4588-acb6-3cb5eda873a8

* hide the button

* fix i18n, format

* hide button

* hide button v2

---------

Co-authored-by: Michel Heusschen <[email protected]>
Co-authored-by: Alex Tran <[email protected]>
@sammyke007
Copy link

Any news on this?

@dharapvj
Copy link

dharapvj commented Oct 6, 2024

Yes -which github issue to track and vote on for server side of this?

@NicholasFlamy
Copy link
Contributor

#11658 seems to be a potential server-side implementation.

@RichardMawdsley
Copy link

Any update on this??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants