GithubHelp home page GithubHelp logo

parse-image's Introduction

parse-image

codecov.io Build Status npm version

Port of Parse Image for parse-env based on node-gm

Auto install imagemagick and graphics magick with homebrew on OS X OR apt if available.

If the auto installation fails, you need to manually install imagemagick and graphicsmagick on you system.

Installation

just install it as a dependency:

$ npm install --save parse-image

There is a pre-install script that will attepmt to use brew or apt to install the imagemagick and graphicsmagick.

If the pre-install script fails, the installation continues but the module may not be working. (actually it won't work at all)

Heroku installation

heroku comes with imagemagick (convert) by default.

You need to manually install heroku-buildpack-graphicsmagick

Follow the instructions in the link and the pre-install warnings should auto-magically disappear

parse-image's People

Contributors

5amfung avatar flovilmart avatar gfpacheco avatar uluru-phatnguyen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

parse-image's Issues

Error signal = null

I'm trying to use this module locally without luck. I get this on the response:

{"code":141,"error":{"code":1,"signal":null}}

no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.

Thanks for creating this repo.
But I wonder if any delegate of imagemagick has to be installed?
I encountered the caption error when executing setData.

Parse.Cloud.httpRequest({ url: url }).then(function(response) {
    // Create an Image from the data.
    var image = new Image();
    return image.setData(response.buffer);
);

Could not execute GraphicsMagick/ImageMagick

I getting this error :

Error generating response. ParseError {
code: 141,
message: [Error: Could not execute GraphicsMagick/ImageMagick: identify "-ping" "-format" "%wx%h" "-" this most likely means the gm/convert binaries can't be found] }

I deployed my application of aws elasticbeanstalk.

Below are cloud code to Generate thumbnail using aws photo url and save thumbnail to parse file

var Image = require("parse-image");
var request = require('request');

Parse.Cloud.define("TestImageCropFuntion", function(request, response) {
var fs = require('fs'),
im = require('imagemagick');
var albumobjct = request.params.imageurl;
// response.success(albumobjct);
var image_url = albumobjct._url;
var image_name = albumobjct.name;
Parse.Cloud.httpRequest({
url: image_url
}).then(function(response) {
var image = new Image();
return image.setData(response.buffer);
}).then(function(image) {
/Crop the image to the smaller of width or height./
var size = Math.min(image.width(), image.height());
return image.crop({
left: (image.width() - size) / 2,
top: (image.height() - size) / 2,
width: size,
height: size
});
}).then(function(image) {
/Resize the image to 64x64./
return image.scale({
width: 500, //250
height: 500 //250
});
}).then(function(image) {
/Make sure it's a JPEG to save disk space and bandwidth./
return image.setFormat("JPEG");
}).then(function(image) {
/* Get the image data in a Buffer.
/
return image.data();
}).then(function(buffer) {
/_Save the image into a new file.*/
var base64 = buffer.toString("base64");
var cropped = new Parse.File(image_name, {
base64: base64
});
return cropped.save({useMasterKey: true});
}).then(function(cropped) {
response.success(cropped._url);
}).then(function(result) {
console.log("result final then" + result);
}, function(error) {
response.error(error);
});
});

Image.data() used to return a Promise

Now it return the data directly.

The change is probably good, but it breaks 100% compatibility with old cloud code.

In my case I changed image.data().then(function(data){...}); with var data = image.data();

Compatibility with parse server 3.0

Parse server 3.0 does no longer contain parse promises but uses the JS promises.

(node:14) UnhandledPromiseRejectionWarning: TypeError: Parse.Promise is not a constructor

error when using amazon s3 adapter

I use the following code to generate thumbnails of my coverarts:

function generateThumbnail(channel, size, coverartAttribute){
	if (!channel.has(coverartAttribute)) {
		var coverartUrl = channel.get("coverart").url();
		if(coverartUrl === ""){
			console.log("coverart url empty. can not generate a thumbnail.");
			return Parse.Promise.as();
		}
		console.log("generating thumbnail for " + channel.get("name") + ". Size: " + coverartAttribute);

		return Parse.Cloud.httpRequest({url: coverartUrl})
		.then(function(response) {
			var image = new Image();
			return image.setData(response.buffer);
		}).then(function(image) {
			return image.scale({ width: size, height: size });
		}).then(function(image) {
			return image.setFormat('JPEG');
		}).then(function(image) {
			return image.data();
		}).then(function(buffer) {
			console.log("Buffer returned, creating Parse File");
			var base64Buffer = buffer.toString("base64");
			var filename = channel.get("coverart").name() + "_thumbnail.jpg";
			var file = new Parse.File(filename, { base64: base64Buffer }, "image/jpeg");
			return file.save();
		}).then(function(file) {
			console.log("Thumbnail saved");
			channel.set(coverartAttribute, file);
		});
	}
	return Parse.Promise.as(); // this is already resolved promise
}

This worked fine as long as the images were stored in mongodb. Now I switched to s3 adapter and I see this error:

2017-05-20T13:14:01.562240+00:00 app[web.1]:   { Error: Command failed:
2017-05-20T13:14:01.562241+00:00 app[web.1]:       at ChildProcess.onExit (/app/node_modules/gm/lib/command.js:289:17)
2017-05-20T13:14:01.562241+00:00 app[web.1]:       at emitTwo (events.js:106:13)
2017-05-20T13:14:01.562241+00:00 app[web.1]:       at ChildProcess.emit (events.js:194:7)
2017-05-20T13:14:01.562241+00:00 app[web.1]:       at maybeClose (internal/child_process.js:899:16)
2017-05-20T13:14:01.562242+00:00 app[web.1]:       at Socket.<anonymous> (internal/child_process.js:342:11)
2017-05-20T13:14:01.562242+00:00 app[web.1]:       at emitOne (events.js:96:13)
2017-05-20T13:14:01.562243+00:00 app[web.1]:       at Socket.emit (events.js:191:7)
2017-05-20T13:14:01.562243+00:00 app[web.1]:       at Pipe._handle.close [as _onclose] (net.js:511:12) code: 1, signal: null },

I confirmed that the coverartUrl is valid and does return a full size coverart image from amazon s3. I confirmed it is no issue with the upload to s3 because the full size coverart images are uploaded to s3 just fine.

It does not log "Buffer returned, creating Parse File".

loading image data from URL with parse-image and Parse.Cloud.httpRequest

I'm trying to use parse-image with the new parse server.
My code in parse cloud load an image from a URL and uses the parse image module library to manipulate it.

return Parse.Cloud.httpRequest({
url: url
}).then(function (response) {
var image = new Image();
return image.setData(response.buffer);
});

The URL I've been using for testing is: http://lorempixel.com/500/500/cats/.
This all work nicely on Parse.com when trying the same code with the local parse server and parse image I notice few things:

  1. the response does not contain buffer anymore. it is just the raw data.
  2. when passing the data to parse-image using image.setData(response); I get an error from gm

Appreciate any help

Thanks,
Simon

In high res images, the height and width are fetched in reverse

I'm using this module just for fetching the width and height of stored images in my parse server.
I've noticed there are times that the width and height are fetched in reverse, meaning the width is the actual height and the height is the actual width!

Here's the function I'm calling inside an afterSave trigger:

var storeImageDimensions = function(postObject) {
	var imageFile = postObject.get("imageLowQuality");
	
	Parse.Cloud.httpRequest({
		url: imageFile.url(),
		success: function(response) {
			// The file contents are in response.buffer.
			var Image = require("parse-image");
			var image = new Image();
			
			// ----------------------------------
			
			image.setData(response.buffer, {
				success: function() {
					var imageDimensions = {};
					
					imageDimensions.width = image.width();
					imageDimensions.height = image.height();
					
					// ----------------------------------
					
					postObject.set("imageDimensions", imageDimensions);
					postObject.save(null, {useMasterKey: true});
				},
				error: function(error) {
				  // The image data was invalid.
				}
			})
		},
		error: function(error) {
		  // The networking request failed.
		}
	});
}

Any idea why's that happening?

AWS Install?

I was hoping that adding these three as dependencies would be all we need to do. Why doesn't just adding dependencies work?

"imagemagick":"*",
"gm":"*",
"parse-image":"*",

Scaling does not take height into consideration.

I'm trying to scale an image without keeping the original ratio.

image.scale({
    width: 1000,
    height: 500
});

So, for instance, if an image has the dimensions 2000 x 800 before scaling, after calling the scale function as indicated above, the resulted image has the dimensions 1000 x 400 instead of 1000 x 500.

ReferenceError: Parse is not defined

I got this error:

/Users/username/node_modules/parse-image/index.js:9
var p = new Parse.Promise();
^
ReferenceError: Parse is not defined
at Image.setData (/Users/username/node_modules/parse-image/index.js:9:14)

Error: "Could not execute GraphicsMagick/ImageMagick: identify "-ping" "-format" "%wx%h" "-" this most likely means the gm/convert binaries can't be found"

Hi @flovilmart ,

I'm getting the following error "Could not execute GraphicsMagick/ImageMagick: identify "-ping" "-format" "%wx%h" "-" this most likely means the gm/convert binaries can't be found" when using parse-image locally.

I have both gm and ImageMagick installed:
convert --version
Version: ImageMagick 6.9.3-0 Q16 x86_64 2016-01-08 http://www.imagemagick.org
gm -version
GraphicsMagick 1.3.23 2015-11-07 Q8 http://www.GraphicsMagick.org/

When I try to run the test in the parse-image test folder, I get the following error:

/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse-image
==> mocha test

  Image
    #pad()
{ [Error: Command failed: gm identify: No decode delegate for this image format (/var/folders/sp/x6ptmcpd6x3djvgh5xyyj9jw0000gp/T/gmv9NvT7).
gm identify: Request did not return an image.
] code: 1, signal: null }
      1) should pad the image without error


  0 passing (35ms)
  1 failing

  1) Image #pad() should pad the image without error:

      Uncaught AssertionError: false == true
      + expected - actual

      -false
      +true

      at test/test.js:35:4
      at Array.wrappedRejectedCallback (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:159:23)
      at ParsePromise.reject (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:89:35)
      at Array.wrappedRejectedCallback (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:175:19)
      at ParsePromise.reject (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:89:35)
      at Array.wrappedRejectedCallback (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:175:19)
      at ParsePromise.reject (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:89:35)
      at Array.wrappedRejectedCallback (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:175:19)
      at ParsePromise.reject (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:89:35)
      at Array.wrappedRejectedCallback (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:175:19)
      at ParsePromise.reject (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/parse/lib/browser/ParsePromise.js:89:35)
      at gm.<anonymous> (index.js:27:6)
      at gm.<anonymous> (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/gm/lib/getters.js:70:16)
      at cb (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/gm/lib/command.js:318:16)
      at ChildProcess.proc.on.onExit (/Users/simon.raveh/Development/Code/Projects/PettingClub/PettingClubParseBackend/node_modules/gm/lib/command.js:293:9)
      at maybeClose (internal/child_process.js:817:16)
      at Socket.<anonymous> (internal/child_process.js:319:11)
      at Pipe._onclose (net.js:469:12)

I know this more a gm/imagemagic issue but any help will be appreciated.

fyi: when I changed index.js from:

var gm = require('gm')

to

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

The test passes. Since I'm new to nodejs, I'm not sure how to build a new version with this change included.

Thanks again for your help,
Simon

Image padding not working consistently

Padding an image does not work correctly if specifying a subset of options from left, right, top, bottom.

e.g.
image.pad({left: 20, top: 20, color: "#F00"});
results in:
lefttoppad

image.pad({top: 20, color: "#F00"});
results in:
toppad

image.pad({right: 20, bottom: 20, color: "#F00"});
results in:
rightbottoompad

Add support for interlacing

To support progressive JPEGs.

From the docs:

-interlace
the type of interlacing scheme

Choices are: None, Line, Plane, or Partition. The default is None.
Use Line to create an interlaced PNG or GIF or progressive JPEG image.

I don't think there's a way to determine the current interlacing setting of an image (to allow auto-detection) so this would've to be an extra parameter for ops (or class level maybe).

Deploying parse-image on Heroku

Hi,

I tried deploying my app to heroku, the parse-image module failed in deployment.

Here is the error:

It looks like the parse-image module is not compatible with Heroku. It tries to use homebrew or sudo to install gm or imagemagick:

remote: > [email protected] preinstall /tmp/build_9ed95ed63f69c34fc0fa215168b807c2/node_modules/.staging/parse-image-5c1fcece21cc52b861c781521b1fc6aa
remote: > ./install.sh
remote:
remote: Cannot install using brew or sudo apt-get
remote: Please install manually

This appears to be a bug in parse-image's detection, since imagemagick is built into the Heroku stack and doesn't need to be installed:

$ heroku run convert --version
Running convert --version on shrouded-oasis-52482... up, run.8515
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

Thanks,
Simon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.