Changed image greyscaling library from sharp to jimp

This commit is contained in:
Andrii Reinvald
2025-06-08 09:34:43 +02:00
parent d774955bb4
commit 5c95da38a6
6 changed files with 862 additions and 125 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 KiB

+848 -118
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -8,11 +8,11 @@
"type": "module",
"dependencies": {
"express": "^5.1.0",
"jimp": "^1.6.0",
"liquidjs": "^10.21.1",
"puppeteer": "^24.9.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"sharp": "^0.34.1",
"tsx": "^4.19.4"
},
"devDependencies": {
+12 -5
View File
@@ -1,10 +1,17 @@
import sharp from "sharp";
import {Jimp} from "jimp";
export async function PNGto1BIT(image: Buffer) {
const data = await sharp(image)
.grayscale()
.raw()
.toBuffer();
// Convert to grayscale
const jimpImage = await Jimp.read(image);
jimpImage.greyscale();
const bit4Data = new Uint8Array(jimpImage.bitmap.data);
// Convert to 1-bit
let data = new Uint8Array(jimpImage.bitmap.width * jimpImage.bitmap.height);
for (let i = 0; i < data.length; i++) {
data[i] = bit4Data[i * 4];
}
// Fixed dimensions to match the device requirements
const DISPLAY_BMP_IMAGE_SIZE = 48062;
+1 -1
View File
@@ -18,7 +18,7 @@ export default function App(data: TemplateDataType) {
<HackerNews style={{width: '100%', height: '100%'}}/>
</div>
<div style={{width: '50%', overflow: 'hidden'}}>
<img style={{height: '100%', marginLeft: '-160px'}} src='/assets/images/wallpaper.jpeg'/>
<img style={{height: '80%', marginLeft: '-50px', marginTop: '10%'}} src='/assets/images/color.jpg'/>
</div>
</div>
}