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

gatsby-plugin-imgix-legacy

v1.2.1

Published

Fork of gatsby-plugin-imgix to make it work with most recent versions of GatsbyJS

Downloads

43

Readme

This package is a fork of gatsby-plugin-imgix developed by Angelo Ashmore. The original package has been replaced by @imgix/gatsby

The official Imgix plugin is based on this package and includes additional features such as gatsby-plugin-image support. Please migrate to @imgix/gatsby.

This repository and npm package exist for those who still need to use the old version for some reason. This version should not be used in new projects. The original package was forked to override dependency incopatibility with gatsby. I arsinclair don't have an intention to further develop this plugin, only to ensure that it can still be installed and ran alongside newer gatsby versions. As the BSD 2-clause license states, this package should be used at your own risk.

gatsby-plugin-imgix-legacy

Gatsby plugin which enables the use of Imgix to apply image transformations at request-time.

For most cases, this plugin can replace the use of gatsby-transformer-sharp and speed up your build times significantly.

Learn more about Imgix on their site.

Status

npm version

Install

npm install --save gatsby-plugin-imgix-legacy

How to use

// gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-plugin-imgix-legacy',
      options: {
        // Imgix source domain. This is required.
        domain: 'example-domain.imgix.net',

        // Imgix source secure URL token. Providing this will automatically
        // secure all of your image URLs. This is required if your source type
        // is a Web Proxy.
        // See: https://docs.imgix.com/setup/securing-images
        //
        // Note that this is a private key and should be hidden behind an
        // environment variable.
        // See: https://www.gatsbyjs.org/docs/environment-variables/#server-side-nodejs
        secureUrlToken: process.env.IMGIX_SECURE_URL_TOKEN,

        // Imgix source type. If your source type is a Web Proxy, set this to
        // "webProxy". Otherwise, you may omit this field. URLs provided to the
        // plugin will automatically be converted to a Web Proxy-compatible URL
        // if set to "webProxy".
        sourceType: 'webProxy',

        // List of fields to copy into `fields` as Imgix images. You may list
        // as many fields as needed.
        fields: [
          {
            // The node type containing the image to copy.
            nodeType: 'MarkdownRemark',

            // Name of the new field to create. If you set this to
            // "featuredImage", a field at `fields.featuredImage` will be
            // created.
            fieldName: 'featuredImage',

            // Function to get the URL in the node. This function should return
            // the URL as a string. If your field contains an array of URLs,
            // change the `getUrl` option name to `getUrls`.
            getUrl: (node) => node.frontmatter.featured_image,
          },
        ],
      },
    },
  ],
}

How to query

Fields setup in your configuration are copied into a fields property on the image's node.

For example, a ShopifyProduct node with an image field named featuredImage could be queried like the following:

Note: Learn to use the GraphQL tool and Ctrl+Spacebar at http://localhost:8000/___graphql to discover the types and properties of your GraphQL model.

query {
  allShopifyProduct {
    nodes {
      id
      fields {
        featuredImage {
          url
        }
      }
    }
  }
}

fields is a special Gatsby field reserved for plugins to add data to existing nodes. If fields does not already exist on your node, it will be added automatically.

See the documentation for createNodeField for more information.

Query image URLs with transformations

Imgix image transformations are applied via URL parameters. The url field accepts an imgixParams argument to build a URL with the provided parameters.

query {
  allShopifyProduct {
    nodes {
      id
      fields {
        featuredImage {
          # 800px width and grayscale
          url(imgixParams: { w: 800, sat: -100 })
        }
      }
    }
  }
}

Query responsive images

Responsive images to display using gatsby-image can be queried using the fixed or fluid field.

Use this pattern where ...ImageFragment is one of the following fragments:

  • GatsbyImgixFixed
  • GatsbyImgixFixed_noBase64
  • GatsbyImgixFluid
  • GatsbyImgixFluid_noBase64

Learn about the different types of responsive images and fragments from gatsby-image’s official docs.

query {
  allShopifyProduct {
    nodes {
      id
      fields {
        featuredImage {
          fluid {
            ...ImageFragment
          }
        }
      }
    }
  }
}

Full example:

query {
  allShopifyProduct {
    nodes {
      id
      fields {
        featuredImage {
          fluid(maxWidth: 1000, maxHeight: 800) {
            ...GatsbyImgixFluid
          }
        }
      }
    }
  }
}

Programmatic use

The following functions are provided to build a gatsby-image-compatible object for fixed and fluid responsive images. These functions are used internally by this plugin to build the gatsby-image objects.

buildImgixFixed

Docs coming soon

buildImgixFluid

Docs coming soon

For plugin developers

gatsby-plugin-imgix-legacy can be used to provide gatsby-image support to your Imgix-backed plugin. Source plugins that serve Imgix URLs, such as gatsby-source-prismic, use this plugin for drop-in support of GraphQL-based image transformations.

The following functions can be used to integrate gatsby-plugin-imgix-legacy with your plugin.

All field config creators generate configs that can be provided to Gatsby's type builders.

createImgixTypes

Creates all types needed by the field config generators, including the shared Fixed and Fluid object types and interfaces.

All types returned by this function must be created to use the field creators. Alternatively, each type can be created individually using the exported functions.

import { GatsbyNode } from 'gatsby'
import { createImgixTypes } from 'gatsby-plugin-imgix-legacy'

export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = async (
  gatsbyContext: CreateSchemaCustomizationArgs,
) => {
  const { actions, cache, schema } = gatsbyContext
  const { createTypes } = actions

  const imgixTypes = createImgixTypes({ cache, schema })

  createTypes(imgixTypes)
}

createImgixUrlFieldConfig

Creates a GraphQL field config object that resolves an Imgix URL string to one with URL parameters.

import { GatsbyNode } from 'gatsby'
import { createImgixUrlFieldConfig } from 'gatsby-plugin-imgix-legacy'

export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = async (
  gatsbyContext: CreateSchemaCustomizationArgs,
) => {
  const { actions, schema } = gatsbyContext
  const { createTypes } = actions

  const ProductType = schema.buildObjectType({
    name: 'Product',
    fields: {
      imageUrl: createImgixUrlFieldConfig({
        resolveUrl: (node) => node.image,
      }),
    },
  })

  createTypes(ProductType)
}

createImgixFixedFieldConfig

Creates a GraphQL field config object that resolves an Imgix URL string to a gatsby-image-compatible FixedObject.

import { GatsbyNode } from 'gatsby'
import { createImgixFixedFieldConfig } from 'gatsby-plugin-imgix-legacy'

export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = async (
  gatsbyContext: CreateSchemaCustomizationArgs,
) => {
  const { actions, cache, schema } = gatsbyContext
  const { createTypes } = actions

  const ProductType = schema.buildObjectType({
    name: 'Product',
    fields: {
      imageFixed: createImgixFixedFieldConfig({
        resolveUrl: (node) => node.image,
        cache,
      }),
    },
  })

  createTypes(ProductType)
}

createImgixFluidFieldConfig

Creates a GraphQL field config object that resolves an Imgix URL string to a gatsby-image-compatible FluidObject.

import { GatsbyNode } from 'gatsby'
import { createImgixFluidFieldConfig } from 'gatsby-plugin-imgix-legacy'

export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = async (
  gatsbyContext: CreateSchemaCustomizationArgs,
) => {
  const { actions, cache, schema } = gatsbyContext
  const { createTypes } = actions

  const ProductType = schema.buildObjectType({
    name: 'Product',
    fields: {
      imageFluid: createImgixFluidFieldConfig({
        resolveUrl: (node) => node.image,
        cache,
      }),
    },
  })

  createTypes(ProductType)
}