add photo rotate

This commit is contained in:
MarcZierle 2022-05-03 18:39:10 +02:00
parent 25f062f82a
commit 2add4c42a2
3 changed files with 57 additions and 15 deletions

View File

@ -10,17 +10,23 @@
ref="cropper" ref="cropper"
/> />
<n-space vertical justify="space-between"> <n-space vertical justify="space-between" class="options_panel">
<div> <div>
<h2>Preview</h2> <h2>Preview</h2>
<n-image <div class="preview_wrapper">
class="preview" <n-image
height="200" class="preview"
:src="preview_data_url" :src="preview_data_url"
/> />
</div>
</div> </div>
<n-checkbox v-model:checked="lock_aspect_ratio">lock aspect ratio to flip chart size?</n-checkbox> <h2 style="margin-top: 3em;">Options</h2>
rotate by {{ rotate_angle }}°
<n-slider v-model:value="rotate_angle" @update:value="update_rotate" :step="1" :min="-180" :max="180" />
<n-checkbox :disabled="free_transform" v-model:checked="lock_aspect_ratio">lock aspect ratio to flip chart size</n-checkbox>
<n-checkbox v-model:checked="free_transform">free transform handles</n-checkbox>
</n-space> </n-space>
</n-space> </n-space>
</div> </div>
@ -45,7 +51,9 @@ export default {
return { return {
preview_data_url: null, preview_data_url: null,
lock_aspect_ratio: true, lock_aspect_ratio: true,
bbox: [] free_transform: false,
bbox: [],
rotate_angle: 0,
} }
}, },
computed: { computed: {
@ -83,21 +91,52 @@ export default {
this.preview_data_url = canvas.toDataURL() this.preview_data_url = canvas.toDataURL()
this.bbox = this.coordinates_to_bbox(coordinates) this.bbox = this.coordinates_to_bbox(coordinates)
}, },
update_rotate() {
this.$refs.cropper.appliedImageTransforms= {
rotate: this.rotate_angle,
flip: {
horizontal: false,
vertical: false,
},
}
},
getResult() { getResult() {
return JSON.parse(JSON.stringify(this.bbox)) return {
bbox: JSON.parse(JSON.stringify(this.bbox)),
rotate: -this.rotate_angle
}
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
h2 {
font-weight: bold;
font-size: 1.2em;
color: #999;
}
.options_panel {
display: inline;
background-color: #f5f5f5;
padding: 1.5em;
border-radius: 1em;
}
.cropper { .cropper {
height: 600px; height: 600px;
width: 600px; width: 600px;
max-width: 80vw;
background: #DDD; background: #DDD;
} }
.preview_wrapper {
width: 20vw;
height: 20vw;
}
.preview { .preview {
max-width: 300px; object-fit: contain;
} }
</style> </style>

View File

@ -31,7 +31,7 @@
<PhotoItem <PhotoItem
v-for="photo in photos[group.id]" v-for="photo in photos[group.id]"
:key="photo.id" :key="photo.id"
width="100" width="150"
:src="photo.cropped_image !== null ? photo.cropped_image : photo.original_image" :src="photo.cropped_image !== null ? photo.cropped_image : photo.original_image"
:can_select="true" :can_select="true"
:init_selection="is_photo_selected(photo.id)" :init_selection="is_photo_selected(photo.id)"

View File

@ -36,13 +36,13 @@
:mask-closable="false" :mask-closable="false"
> >
<n-card <n-card
style="width: 95vw; height: 90vh;" style="width: 95vw; min-height: 90vh;"
title="Adjust Photo Cropping" title="Adjust Photo Cropping"
:bordered="true" :bordered="true"
> >
<PhotoCropper <PhotoCropper
style="max-width:900px;margin:auto;" style="max-width:75vw;margin:auto;"
:src="current_photo_src" :src="current_photo_src"
ref="cropper" ref="cropper"
/> />
@ -248,11 +248,14 @@ export default {
} }
}, },
changeCrop() { changeCrop() {
let bbox = this.$refs.cropper.getResult() let results = this.$refs.cropper.getResult()
let bbox = results.bbox
let rotate = results.rotate
if (bbox && this.current_photo) { if (bbox && this.current_photo) {
this.$store.dispatch('updatePhoto', { this.$store.dispatch('updatePhoto', {
id: this.current_photo, id: this.current_photo,
bbox_coords: bbox bbox_coords: bbox,
rotate: rotate
}).then(()=>{ }).then(()=>{
setTimeout(()=>{ setTimeout(()=>{
this.$store.dispatch('cropPhoto', { this.$store.dispatch('cropPhoto', {