Giter Site home page Giter Site logo

brandonklotz / next-image-trace-loader Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 4.0 2.92 MB

Trace images as SVGs as they load.

Home Page: https://next-image-trace-loader.vercel.app

License: MIT License

JavaScript 18.09% CSS 13.54% TypeScript 68.37%
nextjs next image-trace image-processing image jamstack plugin vercel next-images svgs

next-image-trace-loader's Introduction

Version Downloads MIT License

Next Image Trace Loader

Display a SVG traced image while your images lazy load for NextJS projects.

A wrapper of image-trace-loader and next/image

Was truly inspired by Gatsby sites that use Image Trace and wanted to achieve the same look in my Next projects.

Works out of the box with Next 10, if you need more customization you may want to copy the source and import the dependencies image-trace-loader, file-loader, and url-loader.

Example

View site: https://next-image-trace-loader.vercel.app/

Getting started

Install the component to your project.

yarn add next-image-trace-loader

# or

npm install next-image-trace-loader

Update your next.config.js to trace images as SVGs.

// next.config.js

const tracedImages = {
  test: /\.(png|jpe?g|gif|jp2|webp)$/,
  use: [
    {
      loader: 'image-trace-loader'
    }
  ]
}

module.exports = {
  webpack: (config, options) => {
    config.module.rules.push(tracedImages)
    return config
  }
}

Usage in your project

Basic Usage:

import ImageTrace from "next-image-trace-loader"
import ringPlanet from '../public/planet-1.png'

export default function Home() {
  return (
    <>
      <ImageTrace
        src='/planet-1.png'
        trace={ringPlanet.trace}
        nextImageProps={{width: 800, height: 400}}
      />
    </>
  )
}

When using layout=fill with next/image we need to send in width and height properties that will be styled on the divs that wrap the images.

import ImageTrace from "next-image-trace-loader"
import ringPlanet from '../public/planet-1.png'

export default function Home() {
  return (
    <>
      <ImageTrace
        src='/planet-1.png'
        trace={ringPlanet.trace}
        width='800px'
        height='400px'
        nextImageProps={{layout: 'fill'}}
      />
    </>
  )
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.