Method, system and device for quickly extracting background color of picture and storage medium

By configuring ColorThief in the Vue framework, the background color of images can be obtained and converted in real time, solving the problems of complex image background color extraction and interaction delay in web design, and realizing fast and convenient background color acquisition and rendering.

CN118939237AInactive Publication Date: 2024-11-12海看网络科技(山东)股份有限公司
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411411704.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2024-11-12
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In current web design and development, the process of extracting image background colors is complex and causes delays in front-end and back-end interaction, and existing front-end libraries and frameworks are insufficient to provide a solution.

Method used

Leveraging the reactive features and component-based design of the Vue framework, combined with front-end image processing technology, we can obtain the image status in real time by configuring ColorThief in Vue components, use NodeList objects to get the background color and convert it to hexadecimal color, and define trigger events to render it onto the display component.

Benefits of technology

It enables efficient and convenient extraction of image background colors, improves user experience, simplifies the process, and reduces data interaction delays.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939237A_ABST
    Figure CN118939237A_ABST
Patent Text Reader

Abstract

The invention discloses a method, system and device for rapidly extracting a picture background color and a storage medium, and mainly relates to the technical field of Web application system development. Comprising the following steps: creating a Vue component on a web, and configuring ColorThief in the Vue; uploading the hook function in the Vue component, and obtaining a picture in real time; monitoring the acquired picture state in real time and acquiring a NodeList object; obtaining a picture background color and converting an RGB color into a hexadecimal color by using elements in the NodeList object; the hexadecimal color array is assigned, a trigger event is defined, and after the event is triggered by the web page, the obtained background color is rendered to a component for displaying the color. The method has the beneficial effects that a high-efficiency, convenient and user-friendly picture background color extraction solution is realized by combining a front-end image processing technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Web application system development, and in particular to a method, system, device and storage medium for rapidly extracting the background color of a picture. Background Art

[0002] In the process of Web design and development, it is often necessary to process image materials and extract their background colors for use in scenarios such as page layout, style design or color matching.

[0003] Traditional methods usually rely on image processing software or back-end services to extract background color, which not only increases the complexity of the development process, but may also cause delays in data interaction between the front-end and back-end. In addition, although the existing front-end libraries and frameworks provide rich image processing functions, specialized solutions for image background color extraction are still insufficient.

[0004] Therefore, there is an urgent need for a method, system, device and storage medium for quickly extracting the background color of an image based on the Vue framework to solve the above problems. Summary of the invention

[0005] The purpose of the present invention is to provide a method, system, device and storage medium for quickly extracting the background color of an image. It relies on the responsive characteristics and componentized design of the Vue framework and combines front-end image processing technology to achieve an efficient, convenient and user-friendly solution for extracting the background color of an image.

[0006] In order to achieve the above object, the present invention is implemented through the following technical solutions: On the one hand, a method for quickly extracting the background color of an image is provided, comprising the following steps: S1: Create a Vue component on the web and configure ColorThief in Vue; S2: Upload the hook function in the Vue component to obtain the image in real time; S3: Monitor the acquired image status in real time and obtain the NodeList object; S4: Use the elements in the NodeList object to obtain the background color of the image and convert the RGB color into a hexadecimal color; S5: Assign the hexadecimal color array and define the trigger event. When the web page triggers the event, the obtained background color is rendered to the component that displays the color.

[0007] Preferably, the step S1 of creating a Vue component on the web specifically includes: Create a file upload component and a background color display component; The configuration of ColorThief in Vue specifically includes: Use the npm or yarn command to introduce ColorThief into a Vue-based web project, and add a themeColor property to the Upload component on the page to store the background color.

[0008] Preferably, the step S2 is specifically as follows: uploading the hook function on-success in the Upload component, and using a timer in the hook function on-success to trigger the acquisition of the picture status every 10 milliseconds.

[0009] Preferably, the step S3 is specifically: In obtaining the image status, use the document.querySelectorAll('upload-container img') method of JavaScript to obtain a NodeList object. If the NodeList object is not empty, proceed to step S4; If the NodeList object is empty, the next NodeList object will be retrieved after 10 milliseconds.

[0010] Preferably, in step S4, the image background color is obtained by using the elements in the NodeList object, specifically: Define a colors[] array to store the color of the first element in the NodeList object obtained using the getThemeColor method; Define a method getThemeColor, declare a colorThief object in the getThemeColor method, and use the colorThief.getColor method to get the main color and store it in the array colors[]. When the image element is loaded, directly call the method colorThief.getColor to get the main color and store it in the array colors[]. If the loading is not completed, add an event listener load to the image element. Bind a function to the load listener event to get the main color of the image and store it in colors[].

[0011] Preferably, the conversion of RGB color to hexadecimal color in step S4 is specifically as follows: The returned colors[] array is RGB color, and the Promise.all() function is used to loop through the colors[] array; If color is not empty, directly use the method colorHex to convert it into hexadecimal; If color is empty, you need to set a default color and then convert it to hexadecimal; Store the converted hexadecimal color in returnArray[] and return it.

[0012] Preferably, step S5 is specifically as follows: assigning the hexadecimal color array returnArray[] to the attribute themeColor, and defining a trigger event this.$emit('onSuccess', { themeColor:returnArray[]}) to return to the calling web page, and the web page triggers the event this.$emit('onSuccess', { themeColor: returnArray[]}) to render the obtained background color to the component that displays the color.

[0013] On the other hand, a system for quickly extracting the background color of an image is provided, comprising: The data building module is used to build the environment on the Vue architecture and configure the components on the Vue architecture; The data acquisition module is used to upload the hook function in the Vue component, obtain the image in real time, monitor the status of the obtained image in real time and obtain the NodeList object. At the same time, using the elements in the NodeList object, obtain the background color of the image and convert the RGB color to hexadecimal color; The data trigger module is used to assign values ​​to the hexadecimal color array and define the trigger event. When the web page triggers the event, the obtained background color is rendered to the component that displays the color.

[0014] On the other hand, a device for quickly extracting the background color of an image is provided, comprising a processor and a memory for storing a computer program, wherein when the processor executes the computer program, the steps of any of the above-described methods are implemented.

[0015] On the other hand, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by one or more processors, the steps of any of the above methods are implemented.

[0016] Compared with the prior art, the beneficial effects of the present invention are: 1. After the image is loaded, the function is called immediately to obtain the image background color, which improves user experience, achieves timely feedback, and simplifies the process; 2. If the image is not fully loaded, add an event listener to the image element. When the image is loaded, the binding function is executed immediately, which improves the speed of obtaining the image background color, that is, dynamic interaction. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 is a flow chart of the method of the present invention; Figure 2 It is a flow chart of customizing the background color of a picture of the present invention; Figure 3 It is a schematic diagram of the system structure of the present invention. DETAILED DESCRIPTION

[0018] The present invention will be further described below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not intended to limit the scope of the present invention. In addition, it should be understood that after reading the content taught by the present invention, those skilled in the art can make various changes or modifications to the present invention, and these equivalent forms fall within the scope limited by the application equally.

[0019] In the present invention, terms such as "upper", "lower", "left", "right", "front", "back", "vertical", "horizontal", "side", "bottom", etc. indicate directions or positional relationships based on the directions or positional relationships shown in the accompanying drawings. They are relational words determined only for the convenience of describing the structural relationships of the various parts or elements of the present invention, and do not specifically refer to any part or element in the present invention and should not be understood as limitations on the present invention.

[0020] In the present invention, terms such as "fixed connection", "connected", "connection", etc. should be understood in a broad sense, indicating that it can be fixedly connected, integrally connected or detachably connected; it can be directly connected or indirectly connected through an intermediate medium. Relevant scientific research or technical personnel in this field can determine the specific meanings of the above terms in the present invention according to specific circumstances, and they should not be understood as limiting the present invention.

[0021] Example: like Figure 1-2 As shown, this embodiment provides a method for quickly extracting the background color of an image, comprising the following steps: S1: Create a Vue component on the web and configure ColorThief in Vue; S2: Upload the hook function in the Vue component to obtain the image in real time; S3: Monitor the acquired image status in real time and obtain the NodeList object; S4: Use the elements in the NodeList object to obtain the background color of the image and convert the RGB color into a hexadecimal color; S5: Assign the hexadecimal color array and define the trigger event. When the web page triggers the event, the obtained background color is rendered to the component that displays the color.

[0022] Among them, the creation of the Vue component in step S1 specifically includes: creating a file upload component and a background color display component; the configuration of ColorThief in Vue specifically includes: using the npm or yarn command to introduce ColorThief into a Vue-based web project, and adding a themeColor attribute in the page Upload component to store the background color.

[0023] The step S2 is specifically as follows: upload the hook function on-success in the Upload component, and use a timer in the hook function on-success to trigger the acquisition of the image status every 10 milliseconds, and perform the operation of extracting the background color after the image is successfully uploaded. Therefore, the hook function (on-success) when the file upload of the upload component is monitored is required. Use a timer to monitor the status of the image in real time, and call the method of extracting the background color immediately once the image is successfully loaded.

[0024] The step S3 is specifically as follows: in acquiring the state of the picture, the document.querySelectorAll('upload-container img') method of JavaScript is used to acquire a NodeList object. If the NodeList object is not empty, the process proceeds to step S4; if the NodeList object is empty, the next NodeList object is acquired again after 10 milliseconds.

[0025] In step S4, the background color of the image is obtained by using the elements in the NodeList object. Since the upload component can upload multiple images at a time, the main color of the first image is extracted as the background color by default, specifically: Define a colors[] array to store the color of the first element in the NodeList object obtained using the getThemeColor method; Define a method getThemeColor, declare a colorThief object in the getThemeColor method, and use the colorThief.getColor method to get the main color and store it in the array colors[]. When the image element is loaded, directly call the method colorThief.getColor to get the main color and store it in the array colors[]. If the loading is not completed, add an event listener load to the image element. Bind a function to the load listener event to get the main color of the image and store it in colors[].

[0026] The specific steps of converting the RGB color into a hexadecimal color in step S4 are as follows: First, define the a[] array and use the Promise.all function to loop through the colors[] array. If the color exists, convert the color into hexadecimal and store it in the a[] array. If it does not exist, return a default color value in the a[] array. The specific steps include the following: The returned colors[] array is RGB color, and the Promise.all() function is used to loop through the colors[] array; If color is not empty, directly use the colorHex method to convert it into hexadecimal; if color is empty, you need to set a default color and then convert it into hexadecimal; The step S5 is specifically as follows: assign a color array to themeColor, assign the obtained a[] array to the attribute themeColor after traversing the color array, customize a trigger event this.$emit('onSuccess', { themeColor: a[] array}) and obtain a set of color values ​​by uploading a new attribute themeColor after the picture is uploaded successfully. Then, use the weighted average method to calculate and adjust the brightness according to your needs (some pictures are very bright). Finally, display the converted color on the component with the background color of Vue.

[0027] like Figure 3 As shown, this embodiment also provides a system for quickly extracting the background color of an image, including: The data building module is used to build the environment on the Vue architecture and configure the components on the Vue architecture; The data acquisition module is used to upload the hook function in the Vue component, obtain the image in real time, monitor the status of the obtained image in real time and obtain the NodeList object. At the same time, using the elements in the NodeList object, obtain the background color of the image and convert the RGB color to hexadecimal color; The data trigger module is used to assign values ​​to the hexadecimal color array and define the trigger event. When the web page triggers the event, the obtained background color is rendered to the component that displays the color.

[0028] The contents of the above method embodiments are all applicable to the present system embodiments. The functions specifically implemented by the present system embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0029] This embodiment also provides a device, including: at least one processor; At least one memory for storing at least one program; When the at least one program is executed by at least one processor, the at least one processor implements a method for quickly extracting the background color of an image.

[0030] This embodiment also provides a storage medium, which stores a program. The program is executed by a processor to complete a method for quickly extracting the background color of an image.

[0031] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the described embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.

Claims

1. A method for quickly extracting the background color of an image, characterized in that: The following steps are involved: S1: Create a Vue component on the web and configure ColorThief in Vue; S2: Upload the hook function in the Vue component to obtain the image in real time; S3: Monitor the acquired image status in real time and obtain the NodeList object; S4: Use the elements in the NodeList object to obtain the background color of the image and convert the RGB color into a hexadecimal color; S5: Assign the hexadecimal color array and define the trigger event. When the web page triggers the event, the obtained background color is rendered to the component that displays the color.

2. A method for quickly extracting the background color of an image according to claim 1, characterized in that: The step S1 of creating a Vue component on the web specifically includes: Create a file upload component and a background color display component; The configuration of ColorThief in Vue specifically includes: Use the npm or yarn command to introduce ColorThief into a Vue-based web project, and add a themeColor property to the Upload component on the page to store the background color.

3. A method for quickly extracting the background color of an image according to claim 2, characterized in that: The step S2 is specifically as follows: uploading the hook function on-success in the Upload component, and using a timer in the hook function on-success to trigger the acquisition of the image status every 10 milliseconds.

4. A method for quickly extracting the background color of an image according to claim 3, characterized in that: The step S3 is specifically: In obtaining the image status, use the document.querySelectorAll('upload-container img') method of JavaScript to obtain a NodeList object. If the NodeList object is not empty, proceed to step S4; If the NodeList object is empty, the next NodeList object will be retrieved after 10 milliseconds.

5. A method for quickly extracting the background color of an image according to claim 4, characterized in that: In step S4, the background color of the picture is obtained by using the elements in the NodeList object, specifically: Define a colors[] array to store the color of the first element in the NodeList object obtained using the getThemeColor method; Define a method getThemeColor, declare a colorThief object in the getThemeColor method, and use the colorThief.getColor method to get the main color and store it in the array colors[]. When the image element is loaded, directly call the method colorThief.getColor to get the main color and store it in the array colors[]. If the loading is not completed, add an event listener load to the image element. Bind a function to the load listener event to get the main color of the image and store it in colors[].

6. A method for quickly extracting the background color of an image according to claim 5, characterized in that: The specific steps of converting the RGB color into a hexadecimal color in step S4 are as follows: The returned colors[] array is RGB color, and the Promise.all() function is used to loop through the colors[] array; If color is not empty, directly use the method colorHex to convert it into hexadecimal; If color is empty, you need to set a default color and then convert it to hexadecimal; Store the converted hexadecimal color in returnArray[] and return it.

7. A method for quickly extracting the background color of an image according to claim 6, characterized in that: The step S5 is specifically as follows: assigning the hexadecimal color array returnArray[] to the attribute themeColor, and defining a trigger event this.$emit('onSuccess', { themeColor: returnArray[]}) to return to the calling web page, and the web page triggers the event this.$emit('onSuccess', { themeColor: returnArray[]}) to render the obtained background color to the component that displays the color.

8. A system for quickly extracting the background color of an image, characterized in that: include: The data building module is used to build the environment on the Vue architecture and configure the components on the Vue architecture; The data acquisition module is used to upload the hook function in the Vue component, obtain the image in real time, monitor the status of the obtained image in real time and obtain the NodeList object. At the same time, using the elements in the NodeList object, obtain the background color of the image and convert the RGB color to hexadecimal color; The data trigger module is used to assign values ​​to the hexadecimal color array and define the trigger event. When the web page triggers the event, the obtained background color is rendered to the component that displays the color.

9. A device for quickly extracting the background color of an image, characterized in that: The method comprises a processor and a memory for storing a computer program, wherein when the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by one or more processors, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Method and device for generating editable ER graph

    CN113742432A

  • Application test data acquisition method and device, electronic equipment and storage medium

    CN115129580A

  • Remote component rendering method and system under Vue system and medium

    CN115167851A

  • Transfer of image using hook of drawing command

    JP2005352796A