-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
27 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,33 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { nativeImage, NativeImage, Size } from 'electron'; | ||
import * as fs from 'fs-extra'; | ||
import fetch from 'node-fetch'; | ||
import { FileAccessBase } from './io/file-access.base'; | ||
import sharp from 'sharp'; | ||
|
||
@Injectable() | ||
export class ImageProcessor { | ||
public constructor(private fileAccess: FileAccessBase) {} | ||
|
||
public async convertImageBufferToFileAsync(imageBuffer: Buffer, imagePath: string): Promise<void> { | ||
await fs.writeFile(imagePath, imageBuffer); | ||
} | ||
|
||
public async convertLocalImageToBufferAsync(imagePath: string): Promise<Buffer> { | ||
const imageBuffer: Buffer = await this.fileAccess.getFileContentAsBufferAsync(imagePath); | ||
|
||
return imageBuffer; | ||
return await this.fileAccess.getFileContentAsBufferAsync(imagePath); | ||
} | ||
|
||
public async convertOnlineImageToBufferAsync(imageUrl: string): Promise<Buffer> { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
const response: Response = (await fetch(imageUrl)) as Response; | ||
const imageArrayBuffer: ArrayBuffer = await response.arrayBuffer(); | ||
const imageBuffer: Buffer = Buffer.from(imageArrayBuffer); | ||
|
||
return imageBuffer; | ||
return Buffer.from(imageArrayBuffer); | ||
} | ||
|
||
public convertBufferToImageUrl(imageBuffer: Buffer): string { | ||
return 'data:image/png;base64,' + imageBuffer.toString('base64'); | ||
} | ||
|
||
public resizeImage(imageBuffer: Buffer, maxWidth: number, maxHeight: number, jpegQuality: number): Buffer { | ||
let image: NativeImage = nativeImage.createFromBuffer(imageBuffer); | ||
const imageSize: Size = image.getSize(); | ||
|
||
if (imageSize.width > maxWidth || imageSize.height > maxHeight) { | ||
image = image.resize({ width: maxWidth, height: maxHeight, quality: 'best' }); | ||
} | ||
|
||
return image.toJPEG(jpegQuality); | ||
public async resizeImageAsync(imageBuffer: Buffer, maxWidth: number, maxHeight: number, jpegQuality: number): Promise<Buffer> { | ||
return await sharp(imageBuffer) | ||
.resize(maxWidth, maxHeight) | ||
.jpeg({ | ||
quality: jpegQuality, | ||
}) | ||
.toBuffer(); | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
src/app/services/album-artwork-cache/album-artwork-cache-id-factory.ts
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/app/services/album-artwork-cache/album-artwork-cache-id.spec.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/app/services/album-artwork-cache/album-artwork-cache-id.ts
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
src/app/services/album-artwork-cache/album-artwork-cache.service.base.ts
This file was deleted.
Oops, something went wrong.
142 changes: 0 additions & 142 deletions
142
src/app/services/album-artwork-cache/album-artwork-cache.service.spec.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.