I want to make a simple web photo editor. I need to change the brightness, contrast.
Here’s the code.
<script setup lang="ts">
import { ref } from 'vue'
import { getFromDB } from './db.ts'
const data=ref(getFromDB())
const img=ref<HTMLImageElement>()
const onLighter=()=>img.value.style['filter']='brightness(120%)';
const onDarker=()=>img.value.style['filter']='brightness(80%)';
</script>
<template>
<h1>{{ src===data }}</h1>
<button @click="onLighter">lighter</button>
<button @click="onDarker">darker</button>
<img ref="img" :src="'data:image/jpeg;base64,'+data"/>
</template>
We read the data from the emulation database.
Changing the brightness and contrast on the screen is very easy.
But how do we make the data change?
playground…
3
Answers
The topic of the question is duplicated. Previous question with an answer https://stackoverflow.com...
To have the data "changing" you’ll need some way of sampling the change from the server, either it be polling mechanism or messaging (e.g WebSocket or SSE)
Try to solve this with CSS property i.e.,
filter
You can find more details on filter here
Check this codesandbox demo for image brightness and filter changes in Vue.js
Hope this helps