Gathering detailed insights and metrics for ngx-picture
Gathering detailed insights and metrics for ngx-picture
Gathering detailed insights and metrics for ngx-picture
Gathering detailed insights and metrics for ngx-picture
@mralexandernickel/ngx-picture
ngx-picture-carousel
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.1.0.
@daelmaak/ngx-gallery
<p align="center"> <img width="150px" src="https://raw.githubusercontent.com/daelmaak/ngx-gallery/2bd4e961c590edeeac3cf9a230f504a51b7db8ad/apps/demo/src/assets/icons/logo.png" style="max-width:100%;"> </p> <h1 align="center">Ngx Gallery</h1>
ngx-image-drawing-zone

Properly sized images in next generation formats for Angular
npm install ngx-picture
Typescript
Module System
Node Version
NPM Version
TypeScript (85.65%)
JavaScript (7.62%)
HTML (5.77%)
CSS (0.97%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
8 Stars
66 Commits
2 Watchers
20 Branches
1 Contributors
Updated on Jun 30, 2021
Latest Version
3.0.0
Package Id
ngx-picture@3.0.0
Unpacked Size
67.90 kB
Size
16.85 kB
File Count
25
NPM Version
8.18.0
Node Version
18.17.1
Published on
Aug 24, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
3
An Angular library to help properly size, lazy load images, and use next generation formats.
Help improve app performance and fix common Lighthouse opportunities:
Ready made configurations available for:
For live demos:
Angular 9+
1npm i --save ngx-picture@latest
Angular < 9
1npm i --save ngx-picture@2.0.4
Import NgxPictureModule into app.module.ts and call forRoot suppyling the config.
1import { NgModule } from '@angular/core'; 2import { BrowserModule } from '@angular/platform-browser'; 3import { 4 DEFAULT_BREAKPOINTS, 5 ImageFormat, 6 NgxPictureModule 7} from 'ngx-picture'; 8import { AppComponent } from './app.component'; 9 10// 1: supply a function to create the srcset urls for each breakpoint 11export function srcInterpolator( 12 url: string | undefined, 13 imageFormat: ImageFormat, 14 breakpoint: string, 15 breakpointValue: number 16) { 17 return `${url?.split('.')[0]}-${breakpointValue}.${ 18 imageFormat === 'jpeg' ? 'jpg' : 'webp' 19 }`; 20} 21 22@NgModule({ 23 declarations: [AppComponent], 24 imports: [ 25 BrowserModule, 26 , 27 NgxPictureModule.forRoot({ 28 breakpoints: DEFAULT_BREAKPOINTS, //2. the break points to create sources for 29 imageFormats: ['webp', 'jpeg'], //3. the image formats to create sources for. * 30 srcInterpolator 31 }) 32 ], 33 providers: [], 34 bootstrap: [AppComponent] 35}) 36export class AppModule {}
* Image formats must be in order of precedence. In this example if webp s supported it will be used.
1import { NgModule } from '@angular/core'; 2import { BrowserModule } from '@angular/platform-browser'; 3import { NgxPictureModule, CLOUDINARY_CONFIG } from 'ngx-picture'; 4import { AppComponent } from './app.component'; 5 6@NgModule({ 7 declarations: [AppComponent], 8 imports: [BrowserModule, NgxPictureModule.forRoot(CLOUDINARY_CONFIG)], 9 providers: [], 10 bootstrap: [AppComponent] 11}) 12export class AppModule {}
1<ngx-picture 2 src="assets/images/banner.jpg" 3 alt="test" 4 [lazyLoad]="true" 5></ngx-picture>
If lazyLoad is true the component will use an IntersectionObserver (if it is supported by the browser) to only render the picture element if the component is in view.
*Remember to import the NgxPictureModule into the relevant module.
NgxPictureConfig is generic so you can change the brreakpoint values to anything required in the srcInterPolator function. This example is using the Angular CDK breakpoints for the breakpoint keys.
1import { Breakpoints } from '@angular/cdk/layout'; 2 3export interface Dimensions { 4 h: number; 5 w: number; 6} 7 8const ngxPictureConfig: NgxPictureConfig<Dimensions> = { 9 breakpoints: { 10 [Breakpoints.XSmall]: { h: 10, w: 10 }, 11 [Breakpoints.Medium]: { h: 100, w: 100 }, 12 [Breakpoints.Large]: { h: 200, w: 200 } 13 }, 14 imageFormats: ['webp', 'jpg'], 15 srcInterpolator: ( 16 url: string, 17 imageFormat: ImageFormat, 18 breakpoint: string, 19 breakpointValue: Dimensions 20 ) => `${url}/w:${breakpointValue.w}/h:${breakpointValue.h}` 21}; 22 23export function srcInterpolator( 24 url: string, 25 imageFormat: ImageFormat, 26 breakpoint: string, 27 breakpointValue: number 28) { 29 return `${url.split('.')[0]}-${breakpointValue}.${ 30 imageFormat === 'jpeg' ? 'jpg' : 'webp' 31 }`; 32} 33 34@NgModule({ 35 declarations: [AppComponent], 36 imports: [ 37 BrowserModule.withServerTransition({ appId: 'serverApp' }), 38 BrowserAnimationsModule, 39 MatButtonModule, 40 MatCardModule, 41 MatListModule, 42 NgxPictureModule.forRoot(ngxPictureConfig) 43 ], 44 providers: [], 45 bootstrap: [AppComponent] 46}) 47export class AppModule {}
To use a custom img element provide an ngTemplate called #imgTemplate.
1<ngx-picture 2 src="assets/images/banner.jpg" 3 alt="test" 4 [lazyLoad]="true" 5 #picture 6> 7 <ng-template #imgTemplate let-imageData> 8 <img class="custom-template" [src]="imageData.src" [alt]="imageData.alt" /> 9 </ng-template> 10</ngx-picture>
The data context for the template is:
1{ 2 src: string, 3 alt: string 4}
1<picture class="ngx-picture__picture"> 2 <source 3 srcset="assets/images/banner-300.webp" 4 media="(max-width: 599.99px)" 5 type="image/webp" 6 /> 7 <source 8 srcset="assets/images/banner-600.webp" 9 media="(min-width: 600px) and (max-width: 959.99px)" 10 type="image/webp" 11 /> 12 <source 13 srcset="assets/images/banner-960.webp" 14 media="(min-width: 960px) and (max-width: 1279.99px)" 15 type="image/webp" 16 /> 17 <source 18 srcset="assets/images/banner-1280.webp" 19 media="(min-width: 1280px) and (max-width: 1919.99px)" 20 type="image/webp" 21 /> 22 <source 23 srcset="assets/images/banner-1920.webp" 24 media="(min-width: 1920px)" 25 type="image/webp" 26 /> 27 <source 28 srcset="assets/images/banner-300.jpg" 29 media="(max-width: 599.99px)" 30 type="image/jpeg" 31 /> 32 <source 33 srcset="assets/images/banner-600.jpg" 34 media="(min-width: 600px) and (max-width: 959.99px)" 35 type="image/jpeg" 36 /> 37 <source 38 srcset="assets/images/banner-960.jpg" 39 media="(min-width: 960px) and (max-width: 1279.99px)" 40 type="image/jpeg" 41 /> 42 <source 43 srcset="assets/images/banner-1280.jpg" 44 media="(min-width: 1280px) and (max-width: 1919.99px)" 45 type="image/jpeg" 46 /> 47 <source 48 srcset="assets/images/banner-1920.jpg" 49 media="(min-width: 1920px)" 50 type="image/jpeg" 51 /> 52 <img 53 class="ngx-picture__picture__img" 54 src="assets/images/banner.jpg" 55 alt="test" 56 loading="lazy" 57 /> 58</picture>
The picture element in the component has the class ngx-picture__picture and the img element has the class ngx-picturepictureimg.
1.your-picture-class { 2 .ngx-picture__picture { 3 width: 100%; 4 .ngx-picture__picture__img { 5 width: 100%; 6 } 7 } 8}
To clone this repo and run it locally.
1git clone https://github.com/JayChase/ngx-picture.git 2cd ngx-picture 3npm i 4npm run build
1ng s
1npm run storybook
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
167 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More