Skip to content

Instantly share code, notes, and snippets.

@dvsingh9
Last active July 18, 2022 18:04
Show Gist options
  • Save dvsingh9/177f1e6f2aa7e85c5abd69ea0f4e1111 to your computer and use it in GitHub Desktop.
Save dvsingh9/177f1e6f2aa7e85c5abd69ea0f4e1111 to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
export const S3_BUCKET = 'semuaproduk-data';
export const BASE_URL = 'https://d19la03daa7iyw.cloudfront.net/';
@Injectable({
providedIn: 'root'
})
export class ImageHandlerService {
constructor() {
}
returnUrlForKey(key: string, width: number, height: number, grayscale: boolean): string {
const request = {
bucket: S3_BUCKET,
key, // path to your file on the S3 bucket (ex. photos/face1.png)
edits: {
// smartCrop: true, // uncomment to crop around first face, will return nothing if no face is found
// normalize: true,
grayscale,
sharpen: true,
// blur: 5,
// rotate: 180,
resize: {
width,
height,
fit: 'cover'
}
}
}
const strRequest = JSON.stringify(request);
return BASE_URL + btoa(strRequest);;
}
}
@dvsingh9
Copy link
Author

dvsingh9 commented May 26, 2020

Example:

imageHandlerService.returnUrlForKey(productWrap.product.s3key, productWrap.imageWidth, productWrap.imageHeight, false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment