How to use the gm.prototype function in gm

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 vpdb / server / test / modules / file.helper.js View on Github external
* This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

const readFileSync = require('fs').readFileSync;
const resolve = require('path').resolve;
const gm = require('gm');
const pleasejs = require('pleasejs');

require('bluebird').promisifyAll(gm.prototype);

const rom = resolve(__dirname, '../../data/test/files/hulk.zip');
const vpt = resolve(__dirname, '../../data/test/files/empty.vpt');
const vpt2 = resolve(__dirname, '../../data/test/files/table.vpt');
const mp3 = resolve(__dirname, '../../data/test/files/test.mp3');
const mp4 = resolve(__dirname, '../../data/test/files/afm.f4v');
const avi = resolve(__dirname, '../../data/test/files/afm.avi');

class FileHelper {

	constructor(api) {
		this.api = api;
	}

	/**
	 * Uploads a playfield image.
github vpdb / server / src / app / files / metadata / image.metadata.ts View on Github external
* GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
import gm from 'gm';
import { pick } from 'lodash';

import { RequestState } from '../../common/typings/context';
import { File } from '../file';
import { FileDocument } from '../file.document';
import { FileVariation } from '../file.variations';
import { Metadata } from './metadata';

require('bluebird').promisifyAll(gm.prototype);

export class ImageMetadata extends Metadata {

	public isValid(file: FileDocument, variation?: FileVariation): boolean {
		return File.getMimeTypePrimary(file, variation) === 'image';
	}

	public async getMetadata(requestState: RequestState, file: FileDocument, path: string, variation?: FileVariation): Promise<{ [p: string]: any }> {
		return (gm(path) as any).identifyAsync();
	}

	public serializeDetailed(metadata: { [p: string]: any }): { [p: string]: any } {
		return pick(metadata, 'format', 'size', 'depth', 'JPEG-Quality');
	}

	public serializeVariation(metadata: { [p: string]: any }): { [p: string]: any } {
github vpdb / server / src / app / releases / release.abstract.api.ts View on Github external
import gm from 'gm';
import { DocumentQuery } from 'mongoose';

import { createWriteStream } from 'fs';
import { Api } from '../common/api';
import { ApiError } from '../common/api.error';
import { logger } from '../common/logger';
import { Context, RequestState } from '../common/typings/context';
import { FileDocument } from '../files/file.document';
import { FileUtil } from '../files/file.util';
import { Metadata } from '../files/metadata/metadata';
import { processorQueue } from '../files/processor/processor.queue';
import { state } from '../state';
import { ReleaseDocument } from './release.document';

require('bluebird').promisifyAll(gm.prototype);

export abstract class ReleaseAbstractApi extends Api {

	/**
	 * Retrieves release details.
	 * @param id Database ID of the release to fetch
	 * @returns {Promise.}
	 */
	protected async getDetails(id: string) {
		return this.populateAll(state.models.Release.findById(id)).exec();
	}

	/**
	 * Adds population for release details.
	 *
	 * @param {module:mongoose.DocumentQuery} query
github vpdb / server / src / releases / release.abstract.api.ts View on Github external
import { DocumentQuery } from 'mongoose';
import { promisify } from 'util';

import { Api } from '../common/api';
import { ApiError } from '../common/api.error';
import { logger } from '../common/logger';
import { Context, RequestState } from '../common/typings/context';
import { FileDocument } from '../files/file.document';
import { FileUtil } from '../files/file.util';
import { Metadata } from '../files/metadata/metadata';
import { processorQueue } from '../files/processor/processor.queue';
import { state } from '../state';
import { ReleaseDocument } from './release.document';

const existsAsync = promisify(exists);
require('bluebird').promisifyAll(gm.prototype);

export abstract class ReleaseAbstractApi extends Api {

	/**
	 * Retrieves release details.
	 * @param id Database ID of the release to fetch
	 * @returns {Promise.}
	 */
	protected async getDetails(id: string) {
		return this.populateAll(state.models.Release.findById(id)).exec();
	}

	/**
	 * Adds population for release details.
	 *
	 * @param {module:mongoose.DocumentQuery} query
github vpdb / server / src / modules / processor / directb2s.js View on Github external
'use strict';

const _ = require('lodash');
const fs = require('fs');
const gm = require('gm');
const sax = require('sax');
const logger = require('winston');
const base64 = require('base64-stream');
const PngQuant = require('pngquant');
const Readable = require('stream').Readable;

const Parser = require('../sax-async');
const error = require('../error')('processor', 'directb2s');
const mimeTypes = require('../mimetypes');

Promise.promisifyAll(gm.prototype);

/**
 * Direct B2S Backglass processor
 *
 * Pass 1
 * Extract thumbnails
 *
 * Pass 2
 * Crunch PNG resources with pngquand
 * No optipng for performance reasons, 700% more processing time for 2% less space
 *
 * @constructor
 */
function Directb2sProcessor() {
	this.name = 'directb2s';
	this.variations = {
github vpdb / server / src / app / files / processor / image.variation.processor.ts View on Github external
* You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import { createWriteStream } from 'fs';
import gm from 'gm';

import { logger } from '../../common/logger';
import { RequestState } from '../../common/typings/context';
import { FileDocument } from '../file.document';
import { FileUtil } from '../file.util';
import { FileVariation, ImageFileVariation } from '../file.variations';
import { CreationProcessor } from './processor';

require('bluebird').promisifyAll(gm.prototype);

export class ImageVariationProcessor implements CreationProcessor {

	public name: string = 'image.variation';

	public canProcess(file: FileDocument, srcVariation: FileVariation, destVariation: FileVariation): boolean {
		return file.getMimeTypePrimary(srcVariation) === 'image' && file.getMimeTypePrimary(srcVariation) === 'image';
	}

	public getOrder(variation?: FileVariation): number {
		return 100 + (variation && variation.priority ? variation.priority : 0);
	}

	public async process(requestState: RequestState, file: FileDocument, src: string, dest: string, variation?: ImageFileVariation): Promise {

		logger.debug(requestState, '[ImageVariationProcessor] Start: %s from %s to %s', file.toDetailedString(variation), FileUtil.log(src), FileUtil.log(dest));
github vpdb / server / src / app / files / processor / directb2s.thumb.processor.ts View on Github external
import { createWriteStream } from 'fs';
import gm, { State } from 'gm';
import { Readable } from 'stream';

import { ApiError } from '../../common/api.error';
import { logger } from '../../common/logger';
import { RequestState } from '../../common/typings/context';
import { XmlParser } from '../../common/xml.parser';
import { FileDocument } from '../file.document';
import { mimeTypes } from '../file.mimetypes';
import { BackglassVariation, FileVariation } from '../file.variations';
import { CreationProcessor } from './processor';

const { Base64Decode } = require('base64-stream');

require('bluebird').promisifyAll(gm.prototype);

export class Directb2sThumbProcessor implements CreationProcessor {

	public name: string = 'directb2s.thumb';

	public canProcess(file: FileDocument, srcVariation: FileVariation, destVariation: FileVariation): boolean {
		return file.getMimeType(srcVariation) === 'application/x-directb2s' && file.getMimeCategory(destVariation) === 'image';
	}

	public getOrder(variation?: FileVariation): number {
		return 200 + (variation && variation.priority ? variation.priority : 0);
	}

	public async process(requestState: RequestState, file: FileDocument, src: string, dest: string, variation?: BackglassVariation): Promise {
		const now = Date.now();
		logger.debug(requestState, '[Directb2sThumbProcessor] Starting processing %s at %s.', file.toShortString(variation), dest);
github vpdb / server / src / modules / processor / image.js View on Github external
*/

'use strict';

var _ = require('lodash');
var fs = require('fs');
var logger = require('winston');
var gm = require('gm');

var PngQuant = require('pngquant');
var OptiPng = require('optipng');

var error = require('../error')('processor', 'image');
var mimeTypes = require('../mimetypes');

Promise.promisifyAll(gm.prototype);

/**
 * Image processor.
 *
 * Pass 1
 * Resizes the image
 *
 * Pass 2
 * Crunches PNG files using pngquant and optipng.
 *
 * @constructor
 */
function ImageProcessor() {
	this.name = 'image';

	this.variations = {

gm

GraphicsMagick and ImageMagick for node.js

MIT
Latest version published 2 years ago

Package Health Score

52 / 100
Full package analysis