mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-12 23:05:39 +01:00
add qoi upload support
This commit is contained in:
@@ -3,6 +3,7 @@ import { fileTypeFromBuffer, FileTypeResult } from 'file-type';
|
||||
import { FullMime } from 'picsur-shared/dist/dto/mimes.dto';
|
||||
import { AsyncFailable, HasFailed } from 'picsur-shared/dist/types';
|
||||
import { ParseMime } from 'picsur-shared/dist/util/parse-mime';
|
||||
import { IsQOI } from 'qoi-img';
|
||||
import { ImageDBService } from '../../collections/imagedb/imagedb.service';
|
||||
import { EImageBackend } from '../../models/entities/image.entity';
|
||||
import { ImageProcessorService } from './imageprocessor.service';
|
||||
@@ -66,11 +67,18 @@ export class ImageManagerService {
|
||||
}
|
||||
|
||||
private async getFullMimeFromBuffer(image: Buffer): AsyncFailable<FullMime> {
|
||||
const mime: FileTypeResult | undefined = await fileTypeFromBuffer(image);
|
||||
const filetypeResult: FileTypeResult | undefined = await fileTypeFromBuffer(
|
||||
image,
|
||||
);
|
||||
|
||||
console.log(mime);
|
||||
let mime: string | undefined;
|
||||
if (filetypeResult === undefined) {
|
||||
if (IsQOI(image)) mime = 'image/qoi';
|
||||
} else {
|
||||
mime = filetypeResult.mime;
|
||||
}
|
||||
|
||||
const fullMime = ParseMime(mime?.mime ?? 'extra/discard');
|
||||
const fullMime = ParseMime(mime ?? 'extra/discard');
|
||||
return fullMime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
SupportedMimeCategory
|
||||
} from 'picsur-shared/dist/dto/mimes.dto';
|
||||
import { AsyncFailable, Fail } from 'picsur-shared/dist/types';
|
||||
import { QOIColorSpace, QOIencode } from 'qoi-img';
|
||||
import { QOIColorSpace, QOIdecode, QOIencode } from 'qoi-img';
|
||||
import sharp from 'sharp';
|
||||
import { UsrPreferenceService } from '../../collections/preferencesdb/usrpreferencedb.service';
|
||||
|
||||
@@ -50,10 +50,12 @@ export class ImageProcessorService {
|
||||
sharpImage = this.icoSharp(image);
|
||||
} else if (mime.mime === ImageMime.BMP) {
|
||||
sharpImage = this.bmpSharp(image);
|
||||
} else if (mime.mime === ImageMime.QOI) {
|
||||
sharpImage = this.qoiSharp(image);
|
||||
} else {
|
||||
sharpImage = sharp(image);
|
||||
}
|
||||
mime.mime = ImageMime.PNG;
|
||||
mime.mime = ImageMime.QOI;
|
||||
|
||||
sharpImage = sharpImage.toColorspace('srgb');
|
||||
|
||||
@@ -111,4 +113,16 @@ export class ImageProcessorService {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private qoiSharp(image: Buffer) {
|
||||
const result = QOIdecode(image);
|
||||
|
||||
return sharp(result.pixels, {
|
||||
raw: {
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
channels: result.channels,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user