How to use gm - 10 common examples

To help you get started, we’ve selected a few gm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FreeFeed / freefeed-server / test / integration / models / attachment.js View on Github external
it('should create a proper colored preview from non-sRGB original', async () => {
      const newAttachment = await createAndCheckAttachment(files.colorprofiled, post, user)

      // original colors
      {
        const original = promisifyAll(gm(newAttachment.getPath()))
        const buffer = await original.resize(1, 1).toBufferAsync('RGB')

        buffer.length.should.be.equal(3)
        buffer[0].should.be.within(191, 193)
        buffer[1].should.be.within(253, 255)
        buffer[2].should.be.within(127, 129)
      }

      // thumbnail colors
      {
        const thumbnailFile = newAttachment.getResizedImagePath('t')
        thumbnailFile.should.be.a.file().and.not.empty

        const thumbnail = promisifyAll(gm(thumbnailFile))
        const buffer = await thumbnail.resize(1, 1).toBufferAsync('RGB')
github keybase / client / visdiff / src / index.js View on Github external
compareNext()
      return
    }

    const newPath = `screenshots/${commitRange[1]}/${filename}`
    if (!fs.existsSync(newPath)) {
      results[diffPath] = DIFF_REMOVED
      compareNext()
      return
    }

    const compareOptions = {
      tolerance: 1e-6, // leave a little wiggle room for antialiasing inconsistencies
      file: diffPath,
    }
    gm.compare(oldPath, newPath, compareOptions, (err, isEqual) => {
      if (err) {
        console.log(err)
        process.exit(1)
      }
      results[diffPath] = isEqual ? DIFF_SAME : DIFF_CHANGED
      compareNext()
    })
  }
  compareNext()
github IBM / Predictive-Industrial-Visual-Analysis / analysis.js View on Github external
function analyzeImage(doc, fileName, analyzeCallback) {
    console.log("Starting Analyze Image Method");
    var
    request = require('request'),
    async = require('async'),
    fs = require('fs'),
    gm = require('gm').subClass({
                                imageMagick: true
                                }),
    analysis = {};

    async.parallel([
                    function (callback) {
                    // Write down meta data about the image
                    gm(fileName).size(function (err, size) {
                                      if (err) {
                                      console.log("Image size", err);
                                      } else {
                                      analysis.size = size;
                                      }
                                      callback(null);
                                      });
                    },
github efstathiosntonas / ngx-form / server / controllers / forms.controller.js View on Github external
let express = require('express'),
    fs      = require('fs'),
    fse     = require('fs-extra'),
    mkdirP  = require('mkdirp'),
    multer  = require('multer'),
    crypto  = require('crypto'),
    mime    = require('mime'),
    path    = require('path'),
    config  = require('../config/config'),
    User    = require('../models/user.model'),
    Form    = require('../models/form.model'),
    gm      = require('gm').subClass({imageMagick: true});

process.on('uncaughtException', (err) => {
  console.log(err);
});

// this function deletes the image
let rmDir = (dirPath, removeSelf) => {
  if (removeSelf === undefined)
    removeSelf = true;
  try {
    var files = fs.readdirSync(dirPath);
  }
  catch (e) {
    return;
  }
  if (files.length > 0)
github alex-cory / portfolio / src / apis / github / index.js View on Github external
.size(function (err, size) {
			  if (!err && size.width * size.height > width * height) {
					gm(`../../components/Work/Repo/img/${image}`)
						.resize(width, height)
						.noProfile()
						.write(`../../components/Work/Repo/img/${image}`, function (err) {
						  if (!err)
						  	// console.log('done')
							  accept()
						})
			  }
	    })
	})
github danactive / history / js / admin-image-manipulation.js View on Github external
if (errorNewPath) {
						throw errorNewPath;
					}

					if (require('fs').existsSync(outputPath + filename)) { // file exists
						if (constant.config.debug && constant.config.debug === true) {
							console.log("createThumb: file exists:" + outputPath + filename + ";");
						}
						afterThumbCreated();
						return;
					}
					if (constant.config.debug && constant.config.debug === true) {
						console.log("ifImage resize image: filename="+filename+";");
					}

					require('gm')(sourcePath + filename)
						.resize(dimension.width, dimension.height + ">")
						.gravity('Center')
						.extent(dimension.width, dimension.height)
						.write(outputPath + filename, afterThumbCreated);
				});
			}
github argos-ci / image-difference / src / imageDifference.js View on Github external
import fs from 'fs'
import path from 'path'
import gm from 'gm'
import spawn from 'cross-spawn'
import mkdirp from 'mkdirp'
import tmp from 'tmp'

const gmMagick = gm.subClass({ imageMagick: true })

function transparent(filename, options) {
  if (!options.width || !options.height) {
    throw new Error('Wrong options provided to transparent()')
  }

  const gmImage = gmMagick(filename)
  gmImage.background('transparent') // Fill in new space with white background
  gmImage.gravity('NorthWest') // Anchor image to upper-left
  gmImage.extent(options.width, options.height) // Specify new image size

  return gmImage
}

function getImageSize(filename) {
  return new Promise((accept, reject) => {
github michaelliao / itranswarp.js / controllers / _images.js View on Github external
// image operation.

var
    fs = require('fs'),
    gm = require('gm').subClass({ imageMagick : true });

function calcScaleSize(origin_width, origin_height, resize_width, resize_height, keepAspect) {
    function isEnlarge(tw, th) {
        return origin_width < tw && origin_height < th;
    }

    if (resize_width <= 0 && resize_height <= 0) {
        throw {"name": "Parameter error!"};
    }
    if (keepAspect === undefined) {
        keepAspect = true;
    }
    if (origin_width === resize_width && origin_height === resize_height) {
        return { width: origin_width, height: origin_height, resized: false, enlarge: false };
    }
    var
github jeresig / pharos-images / schemas / Image.js View on Github external
const farmhash = require("farmhash");
const imageinfo = require("imageinfo");
let gm = require("gm");
const async = require("async");

const models = require("../lib/models");
const urls = require("../lib/urls");
const db = require("../lib/db");
const similar = require("../lib/similar");
const config = require("../lib/config");

// Add the ability to provide an explicit bath to the GM binary
/* istanbul ignore if */
if (config.GM_PATH) {
    gm = gm.subClass({appPath: config.GM_PATH});
}

const Image = new db.schema({
    // An ID for the image in the form: SOURCE/IMAGENAME
    _id: String,

    // The date that this item was created
    created: {
        type: Date,
        default: Date.now,
    },

    // The date that this item was updated
    modified: {
        type: Date,
    },
github wusuopu / app-icon-screenshot-generator / src / lib / icon.js View on Github external
'use strict';

const gm = require('gm').subClass({imageMagick: true});
const _ = require('lodash');
const fs = require('fs');
const os = require('os');
const mkdirp = require('mkdirp');
const child_process = require('child_process');
const async = require('async');


let OUT_DIR = os.tmpDir() + '/app-icon/output';

const androidIconSize = {
  // 'web': { w: 512, h: 512 },
  'ldpi': { w: 36, h: 36 },
  'mdpi': { w: 48, h: 48 },
  'hdpi': { w: 72, h: 72 },
  'xhdpi': { w: 96, h: 96 },

gm

GraphicsMagick and ImageMagick for node.js

MIT
Latest version published 2 years ago

Package Health Score

55 / 100
Full package analysis