search
HomeWeb Front-endVue.jsHow to adjust the tone and curve of pictures in Vue?
How to adjust the tone and curve of pictures in Vue?Aug 17, 2023 am 11:49 AM
vue image processingPicture tone adjustmentPicture curve adjustment

How to adjust the tone and curve of pictures in Vue?

How to adjust the tone and curve of pictures in Vue

In Vue development, we often need to adjust the tone and curve of pictures to achieve better Visual effect. This article will introduce how to use Vue and some commonly used libraries to adjust the tone and curve of pictures, and come with code examples.

1. Tone adjustment

Tone adjustment is achieved by changing the color of the picture. In Vue, we can use the CSS filter attribute to adjust the tone.

The following is a simple example that shows how to use Vue and the filter property of CSS to adjust the hue of the image:

<template>
  <div>
    <img src="/static/imghwm/default1.png"  data-src="imageSrc"  class="lazy"  : alt="Original Image">
    <div>
      <label for="hueRange">Hue</label>
      <input type="range" id="hueRange" v-model="hue" min="-180" max="180">
    </div>
    <img src="/static/imghwm/default1.png"  data-src="adjustedImageSrc"  class="lazy"  : alt="Adjusted Image">
  </div>
</template>

<script>
export default {
  data() {
    return {
      imageSrc: 'original.jpg',
      hue: 0
    }
  },
  computed: {
    adjustedImageSrc() {
      return `adjusted.jpg?hue=${this.hue}`;
    }
  }
}
</script>

<style>
img {
  display: block;
  max-width: 100%;
  margin-bottom: 20px;
}

input {
  width: 200px;
}
</style>

In the above code, we use the v-model directive to adjust hue Bind to the range input element so that the sliding slider can change the hue value in real time. Then, through the computed attribute, we splice this value into the adjusted image path.

2. Curve adjustment

Curve adjustment is achieved by changing the brightness, contrast, saturation and other parameters of the picture. In Vue, we can use some JavaScript image processing libraries, such as CamanJS or pica, to perform curve adjustments.

The following is an example using the CamanJS library, showing how to use Vue and CamanJS to adjust the curve of the image:

<template>
  <div>
    <img src="/static/imghwm/default1.png"  data-src="imageSrc"  class="lazy"  : alt="Original Image">
    <div>
      <label for="brightnessRange">Brightness</label>
      <input type="range" id="brightnessRange" v-model="brightness" min="-100" max="100">
    </div>
    <div>
      <label for="contrastRange">Contrast</label>
      <input type="range" id="contrastRange" v-model="contrast" min="-100" max="100">
    </div>
    <div>
      <label for="saturationRange">Saturation</label>
      <input type="range" id="saturationRange" v-model="saturation" min="-100" max="100">
    </div>
    <img src="/static/imghwm/default1.png"  data-src="adjustedImageSrc"  class="lazy"  : alt="Adjusted Image">
  </div>
</template>

<script>
import Caman from 'caman';

export default {
  data() {
    return {
      imageSrc: 'original.jpg',
      brightness: 0,
      contrast: 0,
      saturation: 0,
    }
  },
  computed: {
    adjustedImageSrc() {
      const image = new Image();
      image.src = this.imageSrc;
      const canvas = document.createElement('canvas');
      const context = canvas.getContext('2d');
      context.drawImage(image, 0, 0, image.width, image.height);
      Caman(canvas, function () {
        this.brightness(this.brightness);
        this.contrast(this.contrast);
        this.saturation(this.saturation);
        this.render();
      });
      return canvas.toDataURL();
    }
  }
}
</script>

<style>
img {
  display: block;
  max-width: 100%;
  margin-bottom: 20px;
}

input {
  width: 200px;
}
</style>

In the above code, we use the v-model directive to combine brightness and contrast Bind saturation and range input elements. Then, in the computed attribute, we first draw the original image onto the canvas, then use CamanJS to perform curve adjustment, and finally convert the adjusted image into a Data URL and return it.

Summary:

By using Vue and some image processing libraries, we can easily adjust the tone and curve of the picture. In the above code example, by adjusting the value of the slider, the tone and curve effects of the image can be changed in real time. Developers can customize filter parameters according to needs to achieve cooler effects.

The above is the detailed content of How to adjust the tone and curve of pictures in Vue?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to configure the lifecycle hooks of the component in VueHow to configure the lifecycle hooks of the component in VueMar 04, 2025 pm 03:29 PM

This article clarifies the role of export default in Vue.js components, emphasizing that it's solely for exporting, not configuring lifecycle hooks. Lifecycle hooks are defined as methods within the component's options object, their functionality un

How to configure the watch of the component in Vue export defaultHow to configure the watch of the component in Vue export defaultMar 04, 2025 pm 03:30 PM

This article clarifies Vue.js component watch functionality when using export default. It emphasizes efficient watch usage through property-specific watching, judicious deep and immediate option use, and optimized handler functions. Best practices

What is Vuex and how do I use it for state management in Vue applications?What is Vuex and how do I use it for state management in Vue applications?Mar 11, 2025 pm 07:23 PM

This article explains Vuex, a state management library for Vue.js. It details core concepts (state, getters, mutations, actions) and demonstrates usage, emphasizing its benefits for larger projects over simpler alternatives. Debugging and structuri

How do I create and use custom plugins in Vue.js?How do I create and use custom plugins in Vue.js?Mar 14, 2025 pm 07:07 PM

Article discusses creating and using custom Vue.js plugins, including development, integration, and maintenance best practices.

How do I implement advanced routing techniques with Vue Router (dynamic routes, nested routes, route guards)?How do I implement advanced routing techniques with Vue Router (dynamic routes, nested routes, route guards)?Mar 11, 2025 pm 07:22 PM

This article explores advanced Vue Router techniques. It covers dynamic routing (using parameters), nested routes for hierarchical navigation, and route guards for controlling access and data fetching. Best practices for managing complex route conf

What are the key features of Vue.js (Component-Based Architecture, Virtual DOM, Reactive Data Binding)?What are the key features of Vue.js (Component-Based Architecture, Virtual DOM, Reactive Data Binding)?Mar 14, 2025 pm 07:05 PM

Vue.js enhances web development with its Component-Based Architecture, Virtual DOM for performance, and Reactive Data Binding for real-time UI updates.

How do I configure Vue CLI to use different build targets (development, production)?How do I configure Vue CLI to use different build targets (development, production)?Mar 18, 2025 pm 12:34 PM

The article explains how to configure Vue CLI for different build targets, switch environments, optimize production builds, and ensure source maps in development for debugging.

How do I use Vue with Docker for containerized deployment?How do I use Vue with Docker for containerized deployment?Mar 14, 2025 pm 07:00 PM

The article discusses using Vue with Docker for deployment, focusing on setup, optimization, management, and performance monitoring of Vue applications in containers.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft