mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	chore(deps): adapt to jimp v1
This commit is contained in:
		
							parent
							
								
									3c7ebfd7eb
								
							
						
					
					
						commit
						f648f11153
					
				@ -6,7 +6,7 @@ import protectedSessionService from "./protected_session.js";
 | 
				
			|||||||
import noteService from "./notes.js";
 | 
					import noteService from "./notes.js";
 | 
				
			||||||
import optionService from "./options.js";
 | 
					import optionService from "./options.js";
 | 
				
			||||||
import sql from "./sql.js";
 | 
					import sql from "./sql.js";
 | 
				
			||||||
import jimp from "jimp";
 | 
					import { Jimp } from "jimp";
 | 
				
			||||||
import imageType from "image-type";
 | 
					import imageType from "image-type";
 | 
				
			||||||
import sanitizeFilename from "sanitize-filename";
 | 
					import sanitizeFilename from "sanitize-filename";
 | 
				
			||||||
import isSvg from "is-svg";
 | 
					import isSvg from "is-svg";
 | 
				
			||||||
@ -212,21 +212,19 @@ async function resize(buffer: Buffer, quality: number) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const start = Date.now();
 | 
					    const start = Date.now();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const image = await jimp.read(buffer);
 | 
					    const image = await Jimp.read(buffer);    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (image.bitmap.width > image.bitmap.height && image.bitmap.width > imageMaxWidthHeight) {
 | 
					    if (image.bitmap.width > image.bitmap.height && image.bitmap.width > imageMaxWidthHeight) {
 | 
				
			||||||
        image.resize(imageMaxWidthHeight, jimp.AUTO);
 | 
					        image.resize({ w: imageMaxWidthHeight });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (image.bitmap.height > imageMaxWidthHeight) {
 | 
					    else if (image.bitmap.height > imageMaxWidthHeight) {
 | 
				
			||||||
        image.resize(jimp.AUTO, imageMaxWidthHeight);
 | 
					        image.resize({ h: imageMaxWidthHeight });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    image.quality(quality);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // when converting PNG to JPG, we lose the alpha channel, this is replaced by white to match Trilium white background
 | 
					    // when converting PNG to JPG, we lose the alpha channel, this is replaced by white to match Trilium white background
 | 
				
			||||||
    image.background(0xFFFFFFFF);
 | 
					    image.background = 0xFFFFFFFF;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const resultBuffer = await image.getBufferAsync(jimp.MIME_JPEG);
 | 
					    const resultBuffer = await image.getBuffer("image/jpeg", { quality });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    log.info(`Resizing image of ${resultBuffer.byteLength} took ${Date.now() - start}ms`);
 | 
					    log.info(`Resizing image of ${resultBuffer.byteLength} took ${Date.now() - start}ms`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user