summaryrefslogtreecommitdiff
path: root/src/services/drive/image-processor.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-05-15 21:27:20 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-05-15 21:27:20 +0900
commit3d8bbedf1bbd501d3ad5e3c26e5e5005ed2d8371 (patch)
treefab0aef7b9bc928980e1788cf55867aacd14abb7 /src/services/drive/image-processor.ts
parentResolve #4833 (diff)
downloadmisskey-3d8bbedf1bbd501d3ad5e3c26e5e5005ed2d8371.tar.gz
misskey-3d8bbedf1bbd501d3ad5e3c26e5e5005ed2d8371.tar.bz2
misskey-3d8bbedf1bbd501d3ad5e3c26e5e5005ed2d8371.zip
GIFのサムネイルが生成されないのを修正
#4728
Diffstat (limited to 'src/services/drive/image-processor.ts')
-rw-r--r--src/services/drive/image-processor.ts33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/services/drive/image-processor.ts b/src/services/drive/image-processor.ts
index 89ac331ca1..4b8db0e0c8 100644
--- a/src/services/drive/image-processor.ts
+++ b/src/services/drive/image-processor.ts
@@ -1,4 +1,5 @@
import * as sharp from 'sharp';
+import * as fs from 'fs';
export type IImage = {
data: Buffer;
@@ -10,7 +11,7 @@ export type IImage = {
* Convert to JPEG
* with resize, remove metadata, resolve orientation, stop animation
*/
-export async function ConvertToJpeg(path: string, width: number, height: number): Promise<IImage> {
+export async function convertToJpeg(path: string, width: number, height: number): Promise<IImage> {
const data = await sharp(path)
.resize(width, height, {
fit: 'inside',
@@ -34,7 +35,7 @@ export async function ConvertToJpeg(path: string, width: number, height: number)
* Convert to WebP
* with resize, remove metadata, resolve orientation, stop animation
*/
-export async function ConvertToWebp(path: string, width: number, height: number): Promise<IImage> {
+export async function convertToWebp(path: string, width: number, height: number): Promise<IImage> {
const data = await sharp(path)
.resize(width, height, {
fit: 'inside',
@@ -57,7 +58,7 @@ export async function ConvertToWebp(path: string, width: number, height: number)
* Convert to PNG
* with resize, remove metadata, resolve orientation, stop animation
*/
-export async function ConvertToPng(path: string, width: number, height: number): Promise<IImage> {
+export async function convertToPng(path: string, width: number, height: number): Promise<IImage> {
const data = await sharp(path)
.resize(width, height, {
fit: 'inside',
@@ -73,3 +74,29 @@ export async function ConvertToPng(path: string, width: number, height: number):
type: 'image/png'
};
}
+
+/**
+ * Convert to GIF (Actually just NOP)
+ */
+export async function convertToGif(path: string): Promise<IImage> {
+ const data = await fs.promises.readFile(path);
+
+ return {
+ data,
+ ext: 'gif',
+ type: 'image/gif'
+ };
+}
+
+/**
+ * Convert to APNG (Actually just NOP)
+ */
+export async function convertToApng(path: string): Promise<IImage> {
+ const data = await fs.promises.readFile(path);
+
+ return {
+ data,
+ ext: 'apng',
+ type: 'image/apng'
+ };
+}