npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-image

v1.0.7

Published

Library that lazy load image in regular format and (.webp) in Angular.

Downloads

9

Readme

Description

This library offers an easy way to treat images and deliver excellent performance with multiple image formats in browser context with no error if you are using Server Side Rendering.

Installation

Use the node package manager to install

npm i ngx-image

or

yarn add ngx-image

Usage

First import the Image Module to the module in your project that you will use ngx-image.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { ImageModule } from 'ngx-image';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ImageModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Then, declare a variable that values ​​the image - placeholder and url - and places the value of each image url.:

import { Component } from '@angular/core';

import { Image } from 'ngx-image';

import { environment } from 'src/environments/environment';

@Component({
  selector: 'plop-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  private readonly assets: string;

  images: Image[];
  webpExample: { regular: Image, webp: Image };
  shapeExample: Image;

  constructor() {
    this.assets = `${environment.application.protocol}://${environment.application.host}/${environment.application.assets}`;
    this.images = [
      {
        placeholder: `${this.assets}/images/ironman_1by1_placeholder.jpg`,
        url: `${this.assets}/images/ironman_1by1_url.jpg`
      },
      {
        placeholder: `${this.assets}/images/hulkbuster_1by1_placeholder.jpg`,
        url: `${this.assets}/images/hulkbuster_1by1_url.jpg`
      }
    ];

    this.webpExample = {
      regular: {
        placeholder: `${this.assets}/images/captainamerica_1by1_placeholder.jpg`,
        url: `${this.assets}/images/captainamerica_1by1_url.jpg`
      },
      webp: {
        placeholder: `${this.assets}/images/captainamerica_1by1_placeholder.webp`,
        url: `${this.assets}/images/captainamerica_1by1_url.webp`
      }
    };

    this.shapeExample = {
      placeholder: `${this.assets}/images/blackwidow_placeholder.jpg`
    };

  }

}

Now place the Inputs and their respective variables in the plop-image image component

<ng-template ngFor let-image [ngForOf]="images">
  <plop-image class="image" [regular]="image" [description]="'test'" ratio="1by1"></plop-image>
</ng-template>

<plop-image class="image" [regular]="webpExample.regular" [webp]="webpExample.webp" [description]="'test'" ratio="1by1">
</plop-image>

<plop-image class="image" [regular]="shapeExample" [description]="'test'" ratio="1by1" inshape></plop-image>

Let's style this

:host {
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
}

.image {
  width: 25%;
  margin: 1em;
}

Properties

ImageComponent

  • Selector: [plop-image]

| Name | Description | Nullable | | ---------------- | ------------------ | -------- | | @Input() regular: Image | Image in any regular format (.png, .jpg).| no | | @Input() wep: Image | Image in any webp format.| yes | | @Input() ratio: ImageRatio | Image ratio.| no | | @Input() inshape: boolean | Image object fit in the center. You can set it true or just right it. Default: false. | yes |

Entities

Image

| Attribute | Description | Type | Nullable | | ----------- | --------------- | ---- | -------- | | placeholder | URL of the image to load, this should be the original image, but with a lower quality (to serve as a 'placeholder'), it can be a 100 x 100 resolution to load quickly, few pixels. In the case of only original image (only one URL), this should be either the URL of the original image. | string | no | | url | URL of the image to load, this should be the original image. | string | yes |

Image Ratio

| Image Ratio Type | | ---------------- | | 1by1 | | 16by9 | | 4by3 | | 8by3 |

| Percentage | | ---------- | | Number greater than 0 and less than or equal to 1 |

Dependencies and APIs used to exemplify ngx-image

License

This project is licensed under the MIT License - see the LICENSE file for details