Skip to content

A self-hosted media server and file management system

feat: show image sizes and resolutions

aminnausin455a9e1130f2
diff --git a/app/Http/Resources/ImageResource.php b/app/Http/Resources/ImageResource.php
index 52cbc0c2..d5e54e4a 100644
--- a/app/Http/Resources/ImageResource.php
+++ b/app/Http/Resources/ImageResource.php
@@ -19,6 +19,9 @@ class ImageResource extends JsonResource {
'type' => $this->image_type,
'source' => $this->user_id && $this->image_source === ImageSource::DOWNLOADED ? ImageSource::UPLOADED : $this->image_source,
'blur_hash' => $this->blur_hash,
+ 'width' => $this->width,
+ 'height' => $this->height,
+ 'size' => $this->size,
'user_id' => $this->user_id,
'user' => $this->whenLoaded('user', fn () => $this->user ? new UserResource($this->user) : null),
'created_at' => $this->created_at,
diff --git a/resources/js/components/cards/data/ImageCard.vue b/resources/js/components/cards/data/ImageCard.vue
index ca80bd3b..de84cf5e 100644
--- a/resources/js/components/cards/data/ImageCard.vue
+++ b/resources/js/components/cards/data/ImageCard.vue
@@ -2,7 +2,7 @@
import type { HTMLAttributes } from 'vue';
import type { ImageResource } from '@/contracts/media';
-import { toFormattedDate, toTimeSpan } from '@/service/util';
+import { formatFileSize, toFormattedDate, toTimeSpan } from '@/service/util';
import { CedarDelete2 } from '@/components/cedar-ui/icons';
import { ButtonIcon } from '@/components/cedar-ui/button';
import { computed } from 'vue';
@@ -40,11 +40,11 @@ const deletionDate = computed(() => {
const isDisabled = computed(() => !!deletionDate.value);
const filename = computed(() => props.data.path.split('/').at(-1));
-const tags = computed(() => {
- if (deletionDate.value) return [{ name: `deleted ${toTimeSpan(deletionDate.value)}`, title: toFormattedDate(deletionDate.value) }];
-
+const imageDate = computed(() => {
+ if (deletionDate.value) return { name: `deleted ${toTimeSpan(deletionDate.value)}`, title: toFormattedDate(deletionDate.value) };
const dateUploadedAt = props.data.created_at ? new Date(props.data.created_at) : new Date();
- return [{ name: `${props.data.source} ${toTimeSpan(dateUploadedAt)}`, title: toFormattedDate(dateUploadedAt) }];
+
+ return { name: `${props.data.source} ${toTimeSpan(dateUploadedAt)}`, title: toFormattedDate(dateUploadedAt) };
});
const generatePosterStyle = (url?: string): HTMLAttributes['style'] => {
@@ -169,34 +169,44 @@ const emit = defineEmits({
</ButtonIcon>
</template>
</div>
- <div class="mt-auto w-full">
- <RouterLink
- :to="`/profile/${data.user.id}`"
- :target="'_blank'"
- class="pointer-events-auto flex h-4 w-fit items-center gap-1 opacity-60 transition-opacity duration-200 group-hover:opacity-100"
- v-if="data.user"
- >
- <LazyImage
- :wrapper-class="'w-fit shrink-0 relative size-4 peer'"
- class="hover:ring-primary-muted aspect-square rounded-full object-cover ring-1 ring-transparent transition-shadow duration-200"
- :src="`https://ui-avatars.com/api/?name=${data.user?.name[0] ?? 'S'}&amp;color=7F9CF5&amp;background=random`"
- alt="user"
- />
- <div
- :class="
- cn(
- 'pointer-events-auto flex h-4 items-center overflow-clip rounded-full bg-neutral-900/60 lowercase drop-shadow-md duration-200',
- 'max-w-0 origin-left transition-[max-width,padding] ease-out',
- 'peer-hover:max-w-32 peer-hover:px-1.5 peer-hover:ease-in',
- 'hover:max-w-32 hover:px-1.5 hover:ease-in',
- )
- "
+ <div class="mt-auto flex w-full">
+ <div class="w-full flex-1">
+ <RouterLink
+ :to="`/profile/${data.user.id}`"
+ :target="'_blank'"
+ class="pointer-events-auto flex h-4 w-fit items-center opacity-60 transition-opacity duration-200 group-hover:opacity-100"
+ v-if="data.user"
>
- <span class="w-full truncate">
- {{ data.user?.name ?? 'system' }}
- </span>
- </div>
- </RouterLink>
+ <div class="peer h-4 w-6 shrink-0">
+ <LazyImage
+ :wrapper-class="'w-fit shrink-0 relative size-4'"
+ class="hover:ring-primary-muted aspect-square rounded-full object-cover ring-1 ring-transparent transition-shadow duration-200"
+ :src="`https://ui-avatars.com/api/?name=${data.user?.name[0] ?? 'S'}&amp;color=7F9CF5&amp;background=random`"
+ alt="user"
+ />
+ </div>
+ <div
+ :class="
+ cn(
+ 'pointer-events-auto -ms-2 flex h-4 items-center overflow-clip rounded-full bg-neutral-900/60 lowercase drop-shadow-md duration-200',
+ 'max-w-0 origin-left transition-[max-width,padding,margin] ease-out',
+ 'peer-hover:-ms-1 peer-hover:max-w-32 peer-hover:px-1.5 peer-hover:ease-in',
+ 'hover:-ms-1 hover:max-w-32 hover:px-1.5 hover:ease-in',
+ )
+ "
+ >
+ <span class="w-full truncate">
+ {{ data.user?.name ?? 'system' }}
+ </span>
+ </div>
+ </RouterLink>
+ </div>
+ <div
+ v-if="props.data.width && props.data.height"
+ class="3xl:text-xs pointer-events-none absolute right-2 bottom-2 rounded-full bg-neutral-900/60 px-1.5 py-0.5 font-mono text-[10px] text-white/90 tabular-nums opacity-60 backdrop-blur-sm transition-opacity duration-200 group-hover:opacity-100"
+ >
+ {{ props.data.width }}x{{ props.data.height }}
+ </div>
</div>
</div>
</div>
@@ -216,8 +226,9 @@ const emit = defineEmits({
</Transition>
</div>
- <div class="text-foreground-2 -mt-1 flex w-full flex-wrap items-center gap-1">
- <span class="pointer-events-auto" v-for="tag in tags" :key="tag.name" :title="tag.title">{{ tag.name }}</span>
+ <div class="text-foreground-2 -mt-1 flex w-full items-baseline gap-2">
+ <span v-if="imageDate" class="min-w-0 flex-1 truncate" :title="imageDate.title">{{ imageDate.name }}</span>
+ <span v-if="props.data.size" class="text-foreground-3 shrink-0 font-mono tabular-nums">{{ formatFileSize(props.data.size) }}</span>
</div>
</div>
</div>
diff --git a/resources/js/components/folders/FolderImages.vue b/resources/js/components/folders/FolderImages.vue
index da560c24..d8d8aa2f 100644
--- a/resources/js/components/folders/FolderImages.vue
+++ b/resources/js/components/folders/FolderImages.vue
@@ -43,12 +43,12 @@ const isShowingReplaced = ref(false);
</ButtonBase>
</div>
- <div class="xms:text-sm flex flex-1 flex-col gap-4 text-xs">
+ <div class="xms:text-sm @container flex flex-1 flex-col gap-4 text-xs">
<div
v-if="filteredImages.length > 0"
:class="[
'grid w-full grid-cols-1 gap-2',
- { 'xl:grid-cols-4': filteredImages.length >= 4, 'md:grid-cols-3': filteredImages.length > 2, 'xms:grid-cols-2': filteredImages.length >= 2 },
+ { '@4xl:grid-cols-4': filteredImages.length >= 4, '@[42rem]:grid-cols-3': filteredImages.length > 2, '@sm:grid-cols-2': filteredImages.length >= 2 },
]"
>
<ImageCard v-for="image in filteredImages" :data="image" :key="image.id" :is-read-only="true" :is-primary="image.id == filteredPrimaryId" :is-folder="true" />
diff --git a/resources/js/contracts/media.ts b/resources/js/contracts/media.ts
index 16a57968..f49386ff 100644
--- a/resources/js/contracts/media.ts
+++ b/resources/js/contracts/media.ts
@@ -177,6 +177,9 @@ export interface ImageResource {
type: ImageType;
source: ImageSource;
blur_hash?: string;
+ width?: number;
+ height?: number;
+ size?: number;
user_id?: number;
created_at?: string;
replaced_at?: string;