@paperpic/vue 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+ ---
2
+ title: Attach and scan
3
+ description: A complete example where the user takes a photo of a document or picks a file, straightens and cleans it up in PaperPic, and sends the result to your server, in plain JavaScript, Vue and React.
4
+ ---
5
+
6
+ # Attach and scan
7
+
8
+ Most apps that take documents ask the user for a photo of one, such as a receipt for an expense or a signed form. This example lets the user take the photo or pick a file, edit it in PaperPic, and send the result to your server.
9
+
10
+ `upload` is the function from [Upload to a server](./upload), which sends the image and fails when the server does not accept it.
11
+
12
+ :::tabs key:framework
13
+ == JavaScript
14
+
15
+ ```html
16
+ <label>
17
+ Photo of the document
18
+ <input id="photo" type="file" accept="image/*" capture="environment" />
19
+ </label>
20
+ <div id="viewer" style="height: 480px"></div>
21
+ <p id="status" role="status"></p>
22
+ ```
23
+
24
+ ```ts
25
+ import { PaperPic } from '@paperpic/core'
26
+ import '@paperpic/core/style.css'
27
+
28
+ const input = document.querySelector<HTMLInputElement>('#photo')!
29
+ const status = document.querySelector('#status')!
30
+
31
+ const pic = new PaperPic(document.querySelector<HTMLElement>('#viewer')!, {
32
+ alt: 'The document you attached',
33
+ maxOutputSize: 3000,
34
+ })
35
+
36
+ input.addEventListener('change', () => {
37
+ const file = input.files?.[0]
38
+ input.value = ''
39
+ if (file) {
40
+ status.textContent = ''
41
+ pic.setOptions({ src: file })
42
+ }
43
+ })
44
+
45
+ // The edit starts as soon as the photo is on display
46
+ pic.on('load', () => pic.edit())
47
+
48
+ pic.on('error', ({ phase }) => {
49
+ if (phase === 'load') {
50
+ status.textContent = 'This file is not an image the browser can open'
51
+ }
52
+ })
53
+
54
+ pic.on('apply', async ({ blob, type }) => {
55
+ status.textContent = 'Sending…'
56
+ try {
57
+ await upload(blob, type)
58
+ status.textContent = 'Sent'
59
+ }
60
+ catch {
61
+ status.textContent = 'The document could not be sent'
62
+ }
63
+ })
64
+ ```
65
+
66
+ == Vue
67
+
68
+ ```vue
69
+ <script setup lang="ts">
70
+ import type { ExportedImage, PaperPicEvents } from '@paperpic/vue'
71
+ import { PaperPic } from '@paperpic/vue'
72
+ import { shallowRef, useTemplateRef } from 'vue'
73
+ import '@paperpic/vue/style.css'
74
+
75
+ const pic = useTemplateRef('pic')
76
+ const photo = shallowRef<File>()
77
+ const status = shallowRef('')
78
+
79
+ function choose(event: Event) {
80
+ const input = event.target as HTMLInputElement
81
+ const file = input.files?.[0]
82
+ input.value = ''
83
+ if (file) {
84
+ status.value = ''
85
+ photo.value = file
86
+ }
87
+ }
88
+
89
+ function failed({ phase }: PaperPicEvents['error']) {
90
+ if (phase === 'load') {
91
+ status.value = 'This file is not an image the browser can open'
92
+ }
93
+ }
94
+
95
+ async function send({ blob, type }: ExportedImage) {
96
+ status.value = 'Sending…'
97
+ try {
98
+ await upload(blob, type)
99
+ status.value = 'Sent'
100
+ }
101
+ catch {
102
+ status.value = 'The document could not be sent'
103
+ }
104
+ }
105
+ </script>
106
+
107
+ <template>
108
+ <label>
109
+ Photo of the document
110
+ <input type="file" accept="image/*" capture="environment" @change="choose">
111
+ </label>
112
+ <div v-if="photo" style="height: 480px">
113
+ <PaperPic
114
+ ref="pic"
115
+ :src="photo"
116
+ alt="The document you attached"
117
+ :max-output-size="3000"
118
+ @load="pic?.instance?.edit()"
119
+ @error="failed"
120
+ @apply="send"
121
+ />
122
+ </div>
123
+ <p role="status">
124
+ {{ status }}
125
+ </p>
126
+ </template>
127
+ ```
128
+
129
+ == React
130
+
131
+ ```tsx
132
+ import type { ExportedImage, PaperPicEvents, PaperPicInstance } from '@paperpic/react'
133
+ import { PaperPic } from '@paperpic/react'
134
+ import { useRef, useState } from 'react'
135
+ import '@paperpic/react/style.css'
136
+
137
+ export function AttachDocument() {
138
+ const picRef = useRef<PaperPicInstance>(null)
139
+ const [photo, setPhoto] = useState<File>()
140
+ const [status, setStatus] = useState('')
141
+
142
+ function choose(input: HTMLInputElement) {
143
+ const file = input.files?.[0]
144
+ input.value = ''
145
+ if (file) {
146
+ setStatus('')
147
+ setPhoto(file)
148
+ }
149
+ }
150
+
151
+ function failed({ phase }: PaperPicEvents['error']) {
152
+ if (phase === 'load') {
153
+ setStatus('This file is not an image the browser can open')
154
+ }
155
+ }
156
+
157
+ async function send({ blob, type }: ExportedImage) {
158
+ setStatus('Sending…')
159
+ try {
160
+ await upload(blob, type)
161
+ setStatus('Sent')
162
+ }
163
+ catch {
164
+ setStatus('The document could not be sent')
165
+ }
166
+ }
167
+
168
+ return (
169
+ <>
170
+ <label>
171
+ Photo of the document
172
+ <input type="file" accept="image/*" capture="environment" onChange={event => choose(event.target)} />
173
+ </label>
174
+ {photo && (
175
+ <div style={{ height: 480 }}>
176
+ <PaperPic
177
+ ref={picRef}
178
+ src={photo}
179
+ alt="The document you attached"
180
+ maxOutputSize={3000}
181
+ onLoad={() => picRef.current?.edit()}
182
+ onError={failed}
183
+ onApply={send}
184
+ />
185
+ </div>
186
+ )}
187
+ <p role="status">{status}</p>
188
+ </>
189
+ )
190
+ }
191
+ ```
192
+
193
+ :::
194
+
195
+ ## Notes
196
+
197
+ - `capture="environment"` opens the back camera on phones, and computers ignore it. Without it, phones offer the camera and the photo library, which suits documents the user already has.
198
+ - Emptying the input after each choice lets the user pick the same photo again, such as to start over after Apply.
199
+ - The viewer opens in the edit mode once the photo loads, so the user goes straight to Straighten or Clean up. Leave out the `load` listener to show the photo first.
200
+ - `phase: 'load'` tells a file the browser cannot open, such as a HEIC photo outside Safari, from a failed edit. [Loading images](../guide/loading#formats) lists the formats.
201
+ - The photo stays in the browser until Apply calls `upload`. PaperPic sends nothing on its own.
202
+ - [`maxOutputSize`](../reference/options#maxoutputsize) keeps the upload small. Phone photos have 12 megapixels or more, and documents stay readable at 3000 pixels on the longest side.
@@ -19,6 +19,7 @@ The [`change`](../reference/events#change) event carries the [state](../referenc
19
19
  <button type="button" data-action="edit">Edit</button>
20
20
  <button type="button" data-action="straighten">Straighten</button>
21
21
  <button type="button" data-action="confirmTool">Done</button>
22
+ <button type="button" data-action="cancelTool">Cancel this tool</button>
22
23
  <button type="button" data-action="undo">Undo</button>
23
24
  <button type="button" data-action="cancel">Cancel</button>
24
25
  <button type="button" data-action="apply">Apply</button>
@@ -43,6 +44,7 @@ const actions: Record<string, () => void> = {
43
44
  edit: () => pic.edit(),
44
45
  straighten: () => pic.openTool('perspective'),
45
46
  confirmTool: () => pic.confirmTool(),
47
+ cancelTool: () => pic.cancelTool(),
46
48
  undo: () => pic.undo(),
47
49
  cancel: () => pic.cancel(),
48
50
  apply: () => pic.apply(),
@@ -61,6 +63,7 @@ function update({ status, mode, activeTool, canUndo, canApply, busy }: PaperPicS
61
63
  edit: !editing,
62
64
  straighten: editing && !activeTool,
63
65
  confirmTool: Boolean(activeTool),
66
+ cancelTool: Boolean(activeTool),
64
67
  undo: editing && !activeTool,
65
68
  cancel: editing && !activeTool,
66
69
  apply: editing && !activeTool,
@@ -115,6 +118,9 @@ function refresh() {
115
118
  <button type="button" @click="viewer?.confirmTool()">
116
119
  Done
117
120
  </button>
121
+ <button type="button" @click="viewer?.cancelTool()">
122
+ Cancel this tool
123
+ </button>
118
124
  </template>
119
125
  <template v-else>
120
126
  <button type="button" @click="viewer?.openTool('perspective')">
@@ -173,7 +179,10 @@ export function Receipt() {
173
179
  <button type="button" disabled={state.status !== 'ready'} onClick={() => viewer().edit()}>Edit</button>
174
180
  )}
175
181
  {state.mode === 'edit' && state.activeTool && (
176
- <button type="button" onClick={() => viewer().confirmTool()}>Done</button>
182
+ <>
183
+ <button type="button" onClick={() => viewer().confirmTool()}>Done</button>
184
+ <button type="button" onClick={() => viewer().cancelTool()}>Cancel this tool</button>
185
+ </>
177
186
  )}
178
187
  {state.mode === 'edit' && !state.activeTool && (
179
188
  <>
@@ -203,9 +212,194 @@ export function Receipt() {
203
212
 
204
213
  :::
205
214
 
215
+ ## A slider of your own {#slider}
216
+
217
+ A slider of your own for Clean up opens the tool first. Each move then calls `setThreshold()`, which changes what Clean up shows, and `confirmTool()` keeps the last value as one edit. Here Done also applies the result, and Cancel leaves the edit mode, so these controls are the whole interface.
218
+
219
+ :::tabs key:framework
220
+ == JavaScript
221
+
222
+ ```html
223
+ <button id="clean-up" type="button">Clean up</button>
224
+ <div id="ruler" hidden>
225
+ <label>
226
+ Sensitivity
227
+ <input id="sensitivity" type="range" min="0" max="1" step="0.05" />
228
+ </label>
229
+ <button id="done" type="button">Done</button>
230
+ <button id="cancel" type="button">Cancel</button>
231
+ </div>
232
+ <div id="viewer" style="height: 480px"></div>
233
+ ```
234
+
235
+ ```ts
236
+ import { PaperPic } from '@paperpic/core'
237
+ import '@paperpic/core/style.css'
238
+
239
+ const pic = new PaperPic(document.querySelector<HTMLElement>('#viewer')!, {
240
+ src: '/receipt.jpg',
241
+ alt: 'A receipt',
242
+ toolbar: false,
243
+ })
244
+ const slider = document.querySelector<HTMLInputElement>('#sensitivity')!
245
+
246
+ document.querySelector('#clean-up')!.addEventListener('click', () => {
247
+ pic.edit()
248
+ pic.openTool('threshold')
249
+ })
250
+ slider.addEventListener('input', () => pic.setThreshold({ sensitivity: slider.valueAsNumber }))
251
+ document.querySelector('#done')!.addEventListener('click', () => {
252
+ pic.confirmTool()
253
+ pic.apply()
254
+ })
255
+ document.querySelector('#cancel')!.addEventListener('click', () => {
256
+ pic.cancelTool()
257
+ pic.cancel()
258
+ })
259
+
260
+ pic.on('change', ({ activeTool, threshold }) => {
261
+ const open = activeTool === 'threshold'
262
+ document.querySelector<HTMLElement>('#ruler')!.hidden = !open
263
+ document.querySelector<HTMLElement>('#clean-up')!.hidden = open
264
+ slider.value = String(threshold.sensitivity)
265
+ })
266
+ ```
267
+
268
+ == Vue
269
+
270
+ ```vue
271
+ <script setup lang="ts">
272
+ import type { PaperPicState } from '@paperpic/vue'
273
+ import { PaperPic } from '@paperpic/vue'
274
+ import { computed, shallowRef, useTemplateRef } from 'vue'
275
+ import '@paperpic/vue/style.css'
276
+
277
+ const pic = useTemplateRef<InstanceType<typeof PaperPic>>('pic')
278
+ const viewer = computed(() => pic.value?.instance)
279
+ const state = shallowRef<PaperPicState>()
280
+
281
+ function open() {
282
+ viewer.value?.edit()
283
+ viewer.value?.openTool('threshold')
284
+ }
285
+
286
+ function slide(event: Event) {
287
+ viewer.value?.setThreshold({ sensitivity: (event.target as HTMLInputElement).valueAsNumber })
288
+ }
289
+
290
+ function done() {
291
+ viewer.value?.confirmTool()
292
+ viewer.value?.apply()
293
+ }
294
+
295
+ function cancel() {
296
+ viewer.value?.cancelTool()
297
+ viewer.value?.cancel()
298
+ }
299
+ </script>
300
+
301
+ <template>
302
+ <div v-if="state?.activeTool === 'threshold'">
303
+ <label>
304
+ Sensitivity
305
+ <input type="range" min="0" max="1" step="0.05" :value="state.threshold.sensitivity" @input="slide">
306
+ </label>
307
+ <button type="button" @click="done">
308
+ Done
309
+ </button>
310
+ <button type="button" @click="cancel">
311
+ Cancel
312
+ </button>
313
+ </div>
314
+ <button v-else type="button" :disabled="state?.status !== 'ready'" @click="open">
315
+ Clean up
316
+ </button>
317
+ <div style="height: 480px">
318
+ <PaperPic
319
+ ref="pic"
320
+ src="/receipt.jpg"
321
+ alt="A receipt"
322
+ :toolbar="false"
323
+ @change="next => (state = next)"
324
+ @load="state = viewer?.getState()"
325
+ @error="state = viewer?.getState()"
326
+ />
327
+ </div>
328
+ </template>
329
+ ```
330
+
331
+ == React
332
+
333
+ ```tsx
334
+ import type { PaperPicInstance, PaperPicState } from '@paperpic/react'
335
+ import { PaperPic } from '@paperpic/react'
336
+ import { useRef, useState } from 'react'
337
+ import '@paperpic/react/style.css'
338
+
339
+ export function CleanUpRuler() {
340
+ const picRef = useRef<PaperPicInstance>(null)
341
+ const [state, setState] = useState<PaperPicState>()
342
+ const viewer = () => picRef.current!
343
+
344
+ function open() {
345
+ viewer().edit()
346
+ viewer().openTool('threshold')
347
+ }
348
+
349
+ function done() {
350
+ viewer().confirmTool()
351
+ viewer().apply()
352
+ }
353
+
354
+ function cancel() {
355
+ viewer().cancelTool()
356
+ viewer().cancel()
357
+ }
358
+
359
+ return (
360
+ <>
361
+ {state?.activeTool === 'threshold'
362
+ ? (
363
+ <div>
364
+ <label>
365
+ Sensitivity
366
+ <input
367
+ type="range"
368
+ min="0"
369
+ max="1"
370
+ step="0.05"
371
+ value={state.threshold.sensitivity}
372
+ onChange={event => viewer().setThreshold({ sensitivity: event.target.valueAsNumber })}
373
+ />
374
+ </label>
375
+ <button type="button" onClick={done}>Done</button>
376
+ <button type="button" onClick={cancel}>Cancel</button>
377
+ </div>
378
+ )
379
+ : (
380
+ <button type="button" disabled={state?.status !== 'ready'} onClick={open}>Clean up</button>
381
+ )}
382
+ <div style={{ height: 480 }}>
383
+ <PaperPic
384
+ ref={picRef}
385
+ src="/receipt.jpg"
386
+ alt="A receipt"
387
+ toolbar={false}
388
+ onChange={setState}
389
+ onLoad={() => setState(viewer().getState())}
390
+ onError={() => setState(viewer().getState())}
391
+ />
392
+ </div>
393
+ </>
394
+ )
395
+ }
396
+ ```
397
+
398
+ :::
399
+
206
400
  ## Notes
207
401
 
208
- - With `toolbar: false`, the built-in edit bar is hidden too, so Crop and Straighten show their handles but no Done button. Your interface confirms them with [`confirmTool()`](../reference/methods#confirmtool), as `Enter` does.
402
+ - With `toolbar: false`, the built-in edit bar is hidden too, so Crop and Straighten show their handles but no Done button. Your interface confirms them with [`confirmTool()`](../reference/methods#confirmtool), as `Enter` does. To close them without their changes, call [`cancelTool()`](../reference/methods#canceltool), as `Esc` does.
209
403
  - Sliders of your own can call [`setThreshold()`](../reference/methods#setthreshold) and [`setAdjustments()`](../reference/methods#setadjustments) directly, which adds one edit for each call. To leave one edit for a whole drag, open the tool with [`openTool()`](../reference/methods#opentool) first: the same methods then change what it shows, and `confirmTool()` keeps it.
210
404
  - [`cancel()`](../reference/methods#cancel) does not ask before discarding the edits. Ask the user first if there are some, such as when `canApply` is true.
211
405
  - The keyboard shortcuts keep working with the focus on the viewer. See [Accessibility](../guide/accessibility).
@@ -0,0 +1,191 @@
1
+ ---
2
+ title: Edit in a dialog
3
+ description: A complete example that opens PaperPic in a dialog to edit a photo, and closes the dialog when the user applies or cancels the changes, in plain JavaScript, Vue and React.
4
+ ---
5
+
6
+ # Edit in a dialog
7
+
8
+ Many apps edit a document in a dialog over the page, such as from a list of attachments. This example opens the viewer in a `<dialog>`, starts the edit mode, and closes the dialog when the user applies the changes or cancels them.
9
+
10
+ `upload` is the function from [Upload to a server](./upload).
11
+
12
+ :::tabs key:framework
13
+ == JavaScript
14
+
15
+ ```html
16
+ <button id="open" type="button">Edit the photo</button>
17
+ <dialog id="editor">
18
+ <div id="viewer" style="width: min(90vw, 720px); height: 70vh"></div>
19
+ </dialog>
20
+ ```
21
+
22
+ ```ts
23
+ import { PaperPic } from '@paperpic/core'
24
+ import '@paperpic/core/style.css'
25
+
26
+ const dialog = document.querySelector<HTMLDialogElement>('#editor')!
27
+ const pic = new PaperPic(document.querySelector<HTMLElement>('#viewer')!, {
28
+ src: '/receipt.jpg',
29
+ alt: 'A receipt',
30
+ })
31
+ let editing = false
32
+
33
+ document.querySelector('#open')!.addEventListener('click', () => {
34
+ dialog.showModal()
35
+ pic.edit()
36
+ })
37
+
38
+ // A photo still loading starts the edit once it is on display
39
+ pic.on('load', () => {
40
+ if (dialog.open) {
41
+ pic.edit()
42
+ }
43
+ })
44
+
45
+ // Apply or Cancel ends the edit, and the dialog closes with it
46
+ pic.on('change', ({ mode }) => {
47
+ if (editing && mode === 'view') {
48
+ dialog.close()
49
+ }
50
+ editing = mode === 'edit'
51
+ })
52
+
53
+ // While editing, Esc goes to the viewer, which asks before discarding the changes
54
+ dialog.addEventListener('cancel', (event) => {
55
+ if (editing) {
56
+ event.preventDefault()
57
+ }
58
+ })
59
+
60
+ pic.on('apply', ({ blob, type }) => upload(blob, type))
61
+ ```
62
+
63
+ == Vue
64
+
65
+ ```vue
66
+ <script setup lang="ts">
67
+ import type { PaperPicState } from '@paperpic/vue'
68
+ import { PaperPic } from '@paperpic/vue'
69
+ import { useTemplateRef } from 'vue'
70
+ import '@paperpic/vue/style.css'
71
+
72
+ const dialog = useTemplateRef('dialog')
73
+ const pic = useTemplateRef('pic')
74
+ let editing = false
75
+
76
+ function open() {
77
+ dialog.value?.showModal()
78
+ pic.value?.instance?.edit()
79
+ }
80
+
81
+ // A photo still loading starts the edit once it is on display
82
+ function loaded() {
83
+ if (dialog.value?.open) {
84
+ pic.value?.instance?.edit()
85
+ }
86
+ }
87
+
88
+ // Apply or Cancel ends the edit, and the dialog closes with it
89
+ function changed({ mode }: PaperPicState) {
90
+ if (editing && mode === 'view') {
91
+ dialog.value?.close()
92
+ }
93
+ editing = mode === 'edit'
94
+ }
95
+
96
+ // While editing, Esc goes to the viewer, which asks before discarding the changes
97
+ function keepEditing(event: Event) {
98
+ if (editing) {
99
+ event.preventDefault()
100
+ }
101
+ }
102
+ </script>
103
+
104
+ <template>
105
+ <button type="button" @click="open">
106
+ Edit the photo
107
+ </button>
108
+ <dialog ref="dialog" @cancel="keepEditing">
109
+ <div style="width: min(90vw, 720px); height: 70vh">
110
+ <PaperPic
111
+ ref="pic"
112
+ src="/receipt.jpg"
113
+ alt="A receipt"
114
+ @load="loaded"
115
+ @change="changed"
116
+ @apply="({ blob, type }) => upload(blob, type)"
117
+ />
118
+ </div>
119
+ </dialog>
120
+ </template>
121
+ ```
122
+
123
+ == React
124
+
125
+ ```tsx
126
+ import type { PaperPicInstance, PaperPicState } from '@paperpic/react'
127
+ import type { SyntheticEvent } from 'react'
128
+ import { PaperPic } from '@paperpic/react'
129
+ import { useRef } from 'react'
130
+ import '@paperpic/react/style.css'
131
+
132
+ export function PhotoEditor() {
133
+ const dialogRef = useRef<HTMLDialogElement>(null)
134
+ const picRef = useRef<PaperPicInstance>(null)
135
+ const editing = useRef(false)
136
+
137
+ function open() {
138
+ dialogRef.current?.showModal()
139
+ picRef.current?.edit()
140
+ }
141
+
142
+ // A photo still loading starts the edit once it is on display
143
+ function loaded() {
144
+ if (dialogRef.current?.open) {
145
+ picRef.current?.edit()
146
+ }
147
+ }
148
+
149
+ // Apply or Cancel ends the edit, and the dialog closes with it
150
+ function changed({ mode }: PaperPicState) {
151
+ if (editing.current && mode === 'view') {
152
+ dialogRef.current?.close()
153
+ }
154
+ editing.current = mode === 'edit'
155
+ }
156
+
157
+ // While editing, Esc goes to the viewer, which asks before discarding the changes
158
+ function keepEditing(event: SyntheticEvent<HTMLDialogElement>) {
159
+ if (editing.current) {
160
+ event.preventDefault()
161
+ }
162
+ }
163
+
164
+ return (
165
+ <>
166
+ <button type="button" onClick={open}>Edit the photo</button>
167
+ <dialog ref={dialogRef} onCancel={keepEditing}>
168
+ <div style={{ width: 'min(90vw, 720px)', height: '70vh' }}>
169
+ <PaperPic
170
+ ref={picRef}
171
+ src="/receipt.jpg"
172
+ alt="A receipt"
173
+ onLoad={loaded}
174
+ onChange={changed}
175
+ onApply={({ blob, type }) => upload(blob, type)}
176
+ />
177
+ </div>
178
+ </dialog>
179
+ </>
180
+ )
181
+ }
182
+ ```
183
+
184
+ :::
185
+
186
+ ## Notes
187
+
188
+ - The viewer can live in the dialog while it is closed. It has no size then, and it fits the image as soon as the dialog opens.
189
+ - Opening the dialog starts the edit mode. If the photo is still loading, the `load` event starts it instead.
190
+ - Apply and Cancel end the edit, and the [`change`](../reference/events#change) that follows closes the dialog. If Apply fails, the edit stays open, and so does the dialog.
191
+ - Each opening edits the image on display, which after an Apply is the result. To start from the original every time, call [`reload()`](../reference/methods#reload) before `edit()`.
@@ -116,5 +116,6 @@ export function Form() {
116
116
 
117
117
  - Straighten stores the proportions when the user presses Done, so choose the type before straightening. Changing it later affects only the next straightening.
118
118
  - For a document in landscape, swap the numbers, such as `297 / 210`.
119
+ - The proportions apply to the page as it shows on screen. If the photo is sideways, turn it with Rotate left before you use Straighten, or a sheet in portrait comes out squashed.
119
120
  - Leave `aspectRatio` out for documents without a fixed size, such as receipts, and Straighten estimates them.
120
121
  - [Straighten](../guide/tools/straighten) explains the estimate and how to handle corners that fall outside the photo.