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

@amplifiers/amplify-graphql-process-image-transformer

v1.3.5

Published

This directive allows you to process images.

Downloads

76

Readme

amplify-graphql-process-image-transformer

Description

Add image processing pipeline to your Amplify GraphQL API. For example resize a profile picture to a thumbnail size in order to improve your page load times.

@processImage

This AWS Amplify directive allows you to process images that have been uploaded to your project's S3 bucket. The directive can only be used to resize images for now. The new image is create in the same S3 bucket, with the same key as the original image under a new folder with the name of the original image and new name and new dimensions (ex <key>/resize/thumbnail.png).

Definition

directive @processImage(bucket:String! actions:[AWSJSON!]! ) on FIELD_DEFINITION

Installation

npm install --save @amplifiers/amplify-graphql-process-image-transformer

Import

/amplify/backend/api/<API_NAME>/transform.conf.json

{
  "transformers": [
    "@amplifiers/amplify-graphql-process-image-transformer"
  ]
}

Usage

Append the @processImage directive to a field in your GraphQL schema. The @processImage directive takes a bucket string and actions array.

bucket field specifies the S3 bucket where the images are stored.

actions field specifies the actions to be performed on the image. The actions are defined as an array of objects. Each object has the following fields:

  • type is the type of action to be performed. Currently only resize is supported. The images will be resized to fit inside the dimensions specified in the width and height fields.
  • width is the width of the image in pixels.
  • height is the height of the image in pixels.
  • name is the name of the transformed image. Can be any string. ex: thumbnail, small, medium, etc

The field must be of type AWSURL. And supported image extensions are ["png", "jpeg", "jpg", "webp", "tiff", "tif"].

Example:

First define the model in your schema:

type Product @model {
  id: ID!
  name: String!
  description: String
  image: AWSURL!
    @processImage(
      bucket: "<your_bucket>"
      actions: [
        { type: "resize", name: "thumbnail", width: 100, height: 100 }
        { type: "resize", name: "medium", width: 500, height: 500 }
      ]
    )
}

Next upload the image and update the model with the image url.

    //upload image to S3 bucket and get the url
    const imageLocation = await uploadFileToBucket(file, "album", "public");
    // create a new product model
    const newProduct = await API.graphql({
        query: mutations.createProduct,
        variables: {
            input: {
                name: "test",
                description: "test",
                image: imageLocation,
            },
        },
    });

And once the images are processed, they will be available from the following urls:

Original: https://<your_bucket>.s3.amazonaws.com/public/album/c1170aeb-2235-475d-9795-541fb6e3a9a1.jpeg

Thumbnail: https://<your_bucket>.s3.amazonaws.com/public/album/c1170aeb-2235-475d-9795-541fb6e3a9a1.jpeg/resize/thumbnail.jpeg

Medium: https://<your_bucket>.s3.amazonaws.com/public/album/c1170aeb-2235-475d-9795-541fb6e3a9a1.jpeg/resize/medium.jpeg

For full example see the example folder.

Architecture

alt text

Development and Contributions

Contributions are more than welcome! Please feel free to open an issue or a pull request. Developer docs are here

License

MIT License