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

mongoose-crate-imagemagick

v1.0.6

Published

Perform imagemagick transformations on image files

Downloads

26

Readme

mongoose-crate-imagemagick

Dependency Status devDependency Status Build Status Coverage Status

A mongoose-crate FileProcessor that applies image transformations with ImageMagick.

Prequisites

A modern version of ImageMagick installed and available on the path. You may also need GhostScript, I did on one computer but not on another. YMMV.

Usage

You can pass images through one or more ImageMagick filters:

const mongoose = require('mongoose')
const crate = require('mongoose-crate')
const LocalFS = require('mongoose-crate-localfs')
const ImageMagick = require('mongoose-crate-imagemagick')

const PostSchema = new mongoose.Schema({
  title: String,
  description: String
})

PostSchema.plugin(crate, {
  storage: new LocalFS({
    directory: '/path/to/storage/directory'
  }),
  fields: {
    image: {
      processor: new ImageMagick({
        tmpDir: '/tmp', // Where transformed files are placed before storage, defaults to os.tmpdir()
        formats: ['JPEG', 'GIF', 'PNG'], // Supported formats, defaults to ['JPEG', 'GIF', 'PNG', 'TIFF']
        transforms: {
          original: {
            // keep the original file
          },
          small: {
            resize: '150x150',
            format: '.jpg'
          },
          medium: {
            resize: '250x250',
            format: '.jpg'
          }
        }
      })
    }
  }
})

const Post = mongoose.model('Post', PostSchema)

.. then later:

const post = new Post()
post.attach('image', {path: '/path/to/image'}, (error) => {
  // image is now attached and post.image is populated e.g.:
  // post.image.small.url
  // post.image.medium.url
})

Meta data

mongoose-crate-imagemagick extends the basic meta data added by mongoose-crate to add some image specific fields. It provides the following for each transformation:

{
  width: 120,
  height: 103,
  depth: 8,
  format: 'PNG',
  name: 'dragon.png',
  size: 26887,
  url: 'http://my_bucket.s3.amazonaws.com/folder/4fbaaa31db8cec0923000019-medium.png'
}

ImageMagick transformations

Transformations are achieved by invoking the convert command from ImageMagick and passing all the properties of the transform as arguments.

Example in convert command:

convert source.png -crop 120x120 -blur 5x10 output.png

Example in plugin options:

PostSchema.plugin(crate, {
  ...
  fields: {
    image: {
      processor: new ImageMagick({
        transforms: {
          small: {
            crop: '120x120',
            blur: '5x10'

For more information on available transforms, see the ImageMagick website.

Changing the destination format

You can change the destination format by using the special transform property format with a known file extension like png, jpg, gif, etc:

PostSchema.plugin(crate, {
  ...
  fields: {
    image: {
      processor: new ImageMagick({
        transforms: {
          as_jpeg: {
            format: 'jpg'

Supported formats

By default we'll only try to process a few common image types. The supported list defaults to jpgs, pngs, gifs and tiffs.

This list can be overridden by specifying the formats argument:

PostSchema.plugin(crate, {
  ...
  fields: {
    image: {
      processor: new ImageMagick({
        formats: ['JPEG', 'GIF', 'PNG']

The values should match up with convert's supported formats. To see a list of all formats supported by your ImageMagick install, run:

convert -list format