Robert Schäfer 00da9e8ecb
feat(backend): resize images with imagor (#8558)
* feat(backend): resize images with imagor

Open questions:
* Do we have external URLs for images? E.g. we have them for seeds. But
  in production?

* Do we want to apply image transformations on these as well? My current
implementation does not apply image transformations as of now. If we
want to do that, we will also expose internal URLs in the kubernetes
Cluster to the S3 endpoint to the client.

TODOs:
* The chat component is using a fixed size for all avatars at the moment.
Maybe we can pair-program on this how to implement responsive images in
this component library.

Commits:
* do not replace upload domain url in the database

* fix all webapp specs

* refactor: remove behaviour we won't need

We don't want to apply image transformations on files, right?

* refactor: replace the domain on read not on write

* wip: webapp fixes

* refactor(backend): add another url to config

I've given up. There seems to be no nice way to tell the minio to return
a location which differs from it's host name.

* refactor: add test for s3Service

* refactor(backend): proxy minio via backend in local development

Commits:
* provide tests for message attachments
* remove S3_PUBLIC_URL config value

* refactor: follow @ulfgebhardt's review

* add missing environment variable

---------

Co-authored-by: Ulf Gebhardt <ulf.gebhardt@webcraft-media.de>
2025-08-19 10:11:12 +02:00

103 lines
2.4 KiB
Vue

<template>
<div :class="['profile-avatar', size && `--${this.size}`, !isAvatar && '--no-image']">
<!-- '--no-image' is neccessary, because otherwise we still have a little unwanted boarder araund the image for images with white backgrounds -->
<span class="initials">{{ profileInitials }}</span>
<base-icon v-if="isAnonymous" name="eye-slash" />
<responsive-image
v-if="isAvatar"
:image="profile.avatar"
class="image"
:alt="profile.name"
:title="showProfileNameTitle ? profile.name : ''"
@error="$event.target.style.display = 'none'"
sizes="320px"
/>
</div>
</template>
<script>
import ResponsiveImage from '~/components/ResponsiveImage/ResponsiveImage.vue'
export default {
name: 'ProfileAvatar',
components: {
ResponsiveImage,
},
props: {
size: {
type: String,
required: false,
validator: (value) => {
return value.match(/(small|large)/)
},
},
profile: {
type: Object,
default: null,
},
showProfileNameTitle: {
type: Boolean,
default: true,
},
},
computed: {
isAnonymous() {
return !this.profile || !this.profile.name || this.profile.name.toLowerCase() === 'anonymous'
},
isAvatar() {
// TODO may we could test as well if the image is reachable? otherwise the background gets white and the initails can not be read
return this.profile && this.profile.avatar
},
profileInitials() {
if (this.isAnonymous) return ''
return this.profile.name.match(/\b\w/g).join('').substring(0, 3).toUpperCase()
},
},
}
</script>
<style lang="scss">
.profile-avatar {
position: relative;
height: $size-avatar-base;
width: $size-avatar-base;
border-radius: 50%;
overflow: hidden;
background-color: $background-color-base;
color: $text-color-primary-inverse;
&.--small {
width: $size-avatar-small;
height: $size-avatar-small;
}
&.--large {
width: $size-avatar-large;
height: $size-avatar-large;
font-size: $font-size-xx-large;
}
&.--no-image {
background-color: $color-primary-dark;
}
> .initials,
> .base-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
> .image {
position: relative;
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
background-color: $background-color-base;
}
}
</style>