Skip to content

Instantly share code, notes, and snippets.

@touhidrahman
Created January 25, 2022 11:27
Show Gist options
  • Select an option

  • Save touhidrahman/7f3422f2a11d538d4ba2d1d0ba765cd3 to your computer and use it in GitHub Desktop.

Select an option

Save touhidrahman/7f3422f2a11d538d4ba2d1d0ba765cd3 to your computer and use it in GitHub Desktop.
Sanity Image URL generator
import { Pipe, PipeTransform } from '@angular/core'
import { SanityService } from '@core/services/sanity.service'
import { SanityImageSource } from '@sanity/image-url/lib/types/types'
@Pipe({ name: 'sanityImage' })
export class SanityImagePipe implements PipeTransform {
constructor(private sanityService: SanityService) {}
transform(value: SanityImageSource, width?: number): string {
if (width) {
return this.sanityService.getImageUrlBuilder(value).width(width).url()
}
return this.sanityService.getImageUrlBuilder(value).url()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment