mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
chore: convertHexToRGBA
This commit is contained in:
@@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test';
|
||||
import { Buffer } from 'buffer';
|
||||
import path from 'path';
|
||||
import Jimp from 'jimp';
|
||||
import { convertHexToRGBA } from '../../../../utils/color';
|
||||
|
||||
test.describe('Change colors in png', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
@@ -15,7 +16,8 @@ test.describe('Change colors in png', () => {
|
||||
await fileInput?.setInputFiles(imagePath);
|
||||
|
||||
await page.getByTestId('from-color-input').fill('#FF0000');
|
||||
await page.getByTestId('to-color-input').fill('#0000FF');
|
||||
const toColor = '#0000FF';
|
||||
await page.getByTestId('to-color-input').fill(toColor);
|
||||
|
||||
// Click on download
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
@@ -36,6 +38,6 @@ test.describe('Change colors in png', () => {
|
||||
// Check that the first pixel is transparent
|
||||
const image = await Jimp.read(fileContent);
|
||||
const color = image.getPixelColor(0, 0);
|
||||
expect(color).toBe(0x0000ffff);
|
||||
expect(color).toBe(convertHexToRGBA(toColor));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,3 +20,15 @@ export function areColorsSimilar(
|
||||
|
||||
return colorDistance(color1, color2) <= similarityThreshold;
|
||||
}
|
||||
|
||||
export function convertHexToRGBA(color: string): number {
|
||||
// Remove the leading '#' if present
|
||||
if (color.startsWith('#')) {
|
||||
color = color.slice(1);
|
||||
}
|
||||
|
||||
// Convert the color to a number and add the alpha channel
|
||||
const colorValue = parseInt(color, 16);
|
||||
const alphaChannel = 0xff;
|
||||
return (colorValue << 8) | alphaChannel;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user