skip to Main Content

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


  1. Chosen as BEST ANSWER

    The topic of the question is duplicated. Previous question with an answer https://stackoverflow.com...


  2. 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)

    Login or Signup to reply.
  3. 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

    enter image description here

    Hope this helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search