You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is not really an issue with Parse-Server, rather a cry for help with using Imagemagick instead of Parse-Image in my cloud code functions. Can anyone point me in the right direction to achieve the same as expressed in my old cloud code:
Parse.Cloud.beforeSave("TheClass", function(request, response) {
var theObject= request.object;
Parse.Cloud.httpRequest({
url: theObject.get("img").url()
}).then(function(response) {
var image = new Image();
return image.setData(response.buffer);
}).then(function(image) {
var currentWidth = image.width();
var currentHeight = image.height();
var ratio = currentHeight / currentWidth;
if (currentWidth > 640) {
return image.scale({
width: 640,
height: 640 * ratio
});
} else {
return image;
}
}).then(function(image) {
return image.setFormat("JPEG");
}).then(function(image) {
return image.data();
}).then(function(buffer) {
var base64 = buffer.toString("base64");
var cropped = new Parse.File("thumb.jpeg", { base64: base64 });
return cropped.save();
}).then(function(cropped) {
theObject.set("thumb", cropped);
}).then(function(result) {
response.success();
}, function(error) {
response.error(error);
});
});
@christianmarth Thanks! E.g. in the first link example (EasyImage), how would you initialize an image from the response.buffer like I do in line 8 of my pasted code?
@nitrag@oyvindvol the installation is automated on debian and OSX. Installation in Windows is not working yet. For heroku, you need to add a build pack (as explained in the README)
@flovilmart Nice! So, to use this on a heroku based install of parse-server, i just add imagemagick , graphicsmagick and your parse-image to my package.json, and add var Image = require("parse-image") to the top of my cloud code file?
@flovilmart Ok, so now I did only the "Heroku installation" part, and after deploy the heroku logs say "Cannot find module 'parse-image'". Then I added 'parse-image' as a dependency in package.json, and I still get "cannot find module 'parse-image'" in the logs.
I haven`t tested locally, I am just trying to set it up on my parse-server-example that I deployed directly to Heroku. I configured the heroku-buildpack-graphicsmagick via git bash, and push to heroku master. I can see that the buildpack is installed, but am I also supposed to put something in my package.json for it to work in my cloud code?
the build pack is installing the binaries required to parse-image to work correctly.
When you push to heroku, you you see parse-image being installed? Can you give me the heroku logs?
Ok, starting from fresh. I added the buildpack in git bash. I remove everything regarding parse-image from my package.json, then i do git push heroku master. This shows in the console:
2016-02-25T13:44:26.959982+00:00 heroku[api]: Release v140 created by
2016-02-25T13:44:27.098280+00:00 heroku[slug-compiler]: Slug compilation started
2016-02-25T13:44:27.098284+00:00 heroku[slug-compiler]: Slug compilation finished
2016-02-25T13:44:27.472830+00:00 heroku[web.1]: State changed from crashed to starting
2016-02-25T13:44:31.180828+00:00 heroku[web.1]: Starting process with command `npm start`
2016-02-25T13:44:34.223438+00:00 app[web.1]:
2016-02-25T13:44:34.223454+00:00 app[web.1]: > parse-server-example@1.0.0 start /app
2016-02-25T13:44:34.223455+00:00 app[web.1]: > node index.js
2016-02-25T13:44:34.223456+00:00 app[web.1]:
2016-02-25T13:44:35.351267+00:00 app[web.1]: npm ERR! Linux 3.13.0-77-generic
2016-02-25T13:44:35.351727+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-02-25T13:44:35.352006+00:00 app[web.1]: npm ERR! node v5.6.0
2016-02-25T13:44:35.352641+00:00 app[web.1]: npm ERR! npm v3.6.0
2016-02-25T13:44:35.352863+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-02-25T13:44:35.353074+00:00 app[web.1]: npm ERR! parse-server-example@1.0.0 start: `node index.js`
2016-02-25T13:44:35.353260+00:00 app[web.1]: npm ERR! Exit status 1
2016-02-25T13:44:35.353469+00:00 app[web.1]: npm ERR!
2016-02-25T13:44:35.353663+00:00 app[web.1]: npm ERR! Failed at the parse-server-example@1.0.0 start script 'node index.js'.
2016-02-25T13:44:35.353868+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-02-25T13:44:35.354073+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the parse-server-example package,
2016-02-25T13:44:35.354285+00:00 app[web.1]: npm ERR! not with npm itself.
2016-02-25T13:44:35.354466+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-02-25T13:44:35.354682+00:00 app[web.1]: npm ERR! node index.js
2016-02-25T13:44:35.354864+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-02-25T13:44:35.355304+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-02-25T13:44:35.361157+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-02-25T13:44:35.361327+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-02-25T13:44:35.360891+00:00 app[web.1]:
2016-02-25T13:44:35.355700+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-02-25T13:44:35.355092+00:00 app[web.1]: npm ERR! npm bugs parse-server-example
2016-02-25T13:44:35.355515+00:00 app[web.1]: npm ERR! npm owner ls parse-server-example
2016-02-25T13:44:35.329120+00:00 app[web.1]: module.js:341
2016-02-25T13:44:35.329124+00:00 app[web.1]: throw err;
2016-02-25T13:44:35.329125+00:00 app[web.1]: ^
2016-02-25T13:44:35.329125+00:00 app[web.1]:
2016-02-25T13:44:35.329126+00:00 app[web.1]: Error: Cannot find module 'parse-image'
2016-02-25T13:44:35.329128+00:00 app[web.1]: at Function.Module._load (module.js:290:25)
2016-02-25T13:44:35.329127+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:339:15)
2016-02-25T13:44:35.329129+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-02-25T13:44:35.329129+00:00 app[web.1]: at require (internal/module.js:16:19)
2016-02-25T13:44:35.329131+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-02-25T13:44:35.329130+00:00 app[web.1]: at Object.<anonymous> (/app/cloud/main.js:1:75)
2016-02-25T13:44:35.329131+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-02-25T13:44:35.329132+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-02-25T13:44:35.329132+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-02-25T13:44:35.329133+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-02-25T13:44:35.340090+00:00 app[web.1]:
2016-02-25T13:44:36.035081+00:00 heroku[web.1]: State changed from crashed to starting
2016-02-25T13:44:36.033934+00:00 heroku[web.1]: State changed from starting to crashed
2016-02-25T13:44:36.030078+00:00 heroku[web.1]: Process exited with status 1
2016-02-25T13:45:58.111674+00:00 heroku[web.1]: Starting process with command `npm start`
2016-02-25T13:46:00.447983+00:00 app[web.1]: > node index.js
2016-02-25T13:46:00.447984+00:00 app[web.1]:
2016-02-25T13:46:00.447981+00:00 app[web.1]: > parse-server-example@1.0.0 start /app
2016-02-25T13:46:00.447964+00:00 app[web.1]:
2016-02-25T13:46:01.919098+00:00 app[web.1]: npm ERR! Linux 3.13.0-77-generic
2016-02-25T13:46:01.901180+00:00 app[web.1]: module.js:341
2016-02-25T13:46:01.901184+00:00 app[web.1]:
2016-02-25T13:46:01.901186+00:00 app[web.1]: at Function.Module._load (module.js:290:25)
2016-02-25T13:46:01.901190+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-02-25T13:46:01.919662+00:00 app[web.1]: npm ERR! node v5.6.0
2016-02-25T13:46:01.920572+00:00 app[web.1]: npm ERR!
2016-02-25T13:46:01.901189+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-02-25T13:46:01.920799+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-02-25T13:46:01.921630+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-02-25T13:46:01.920445+00:00 app[web.1]: npm ERR! Exit status 1
2016-02-25T13:46:01.901183+00:00 app[web.1]: ^
2016-02-25T13:46:01.901186+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-02-25T13:46:01.921130+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-02-25T13:46:01.901188+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-02-25T13:46:01.901185+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:339:15)
2016-02-25T13:46:01.920340+00:00 app[web.1]: npm ERR! parse-server-example@1.0.0 start: `node index.js`
2016-02-25T13:46:01.901187+00:00 app[web.1]: at require (internal/module.js:16:19)
2016-02-25T13:46:01.921412+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-02-25T13:46:01.901185+00:00 app[web.1]: Error: Cannot find module 'parse-image'
2016-02-25T13:46:01.920061+00:00 app[web.1]: npm ERR! npm v3.6.0
2016-02-25T13:46:01.920218+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-02-25T13:46:01.901182+00:00 app[web.1]: throw err;
2016-02-25T13:46:01.921287+00:00 app[web.1]: npm ERR! node index.js
2016-02-25T13:46:01.901190+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-02-25T13:46:01.901188+00:00 app[web.1]: at Object.<anonymous> (/app/cloud/main.js:1:75)
2016-02-25T13:46:01.921847+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-02-25T13:46:01.901189+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-02-25T13:46:01.919493+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-02-25T13:46:01.911119+00:00 app[web.1]:
2016-02-25T13:46:01.921026+00:00 app[web.1]: npm ERR! not with npm itself.
2016-02-25T13:46:01.921739+00:00 app[web.1]: npm ERR! npm owner ls parse-server-example
2016-02-25T13:46:01.920685+00:00 app[web.1]: npm ERR! Failed at the parse-server-example@1.0.0 start script 'node index.js'.
2016-02-25T13:46:01.921524+00:00 app[web.1]: npm ERR! npm bugs parse-server-example
2016-02-25T13:46:01.925610+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-02-25T13:46:01.920921+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the parse-server-example package,
2016-02-25T13:46:01.925509+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-02-25T13:46:01.925339+00:00 app[web.1]:
2016-02-25T13:46:02.554694+00:00 heroku[web.1]: Process exited with status 1
2016-02-25T13:46:02.564724+00:00 heroku[web.1]: State changed from starting to crashed
I used jimp to replace parse-image when I migrated our app. It is written entirely in JavaScript for Node so no external dependencies needed (no special install on heroku or windows). It probably has worse performance than imagemagick, but I have yet to run any benchmarks. We are scaling a lot of images in our app however and so far it looks promising.
@simonbengtsson That looks lightweight and good. Are you using jimp to e.g. save thumbnails via cloud code? I am having trouble getting that work. With the code provided below, everything seems OK, and the thumb is saved on the "Message" object, but viewing the thumb in the browser with the file URL is not working.
var Jimp = require("jimp");
Parse.Cloud.beforeSave("Message", function(request, response) {
var obj = request.object;
if (!obj .get("img")) {
response.success();
return;
}
Jimp.read(obj.get("img").url())
.then(function(image) {
var currentWidth = image.bitmap.width;
var currentHeight = image.bitmap.height;
var ratio = currentHeight / currentWidth;
if (currentWidth > 640) {
return image.resize(640, 640 * ratio)
} else {
return image;
}
})
.then(function(image) {
console.log("### 1");
var base64 = image.hash();
var cropped = new Parse.File("thumb.jpeg", { base64: base64 });
return cropped.save();
})
.then(function(cropped) {
console.log("### 2");
obj.set("thumb", cropped);
})
.then(function(result) {
console.log("### 3");
response.success();
}, function(error) {
console.log("### 4 ERROR: " + error);
response.error(error);
})
.catch(function (err) {
console.log("### 5 ERROR: " + err);
});
});
Yes we are generating thumbnails in cloud code using jimp. Your issue is probably that the string from image.hash() cannot be used as data for parse files. Try something like this instead:
@flovilmart I tried your parse-image module on Heroku for a simple thumbnail generation. I did not need to change a single line of code, only added "parse-image": "~0.1.1" in my package.json dependencies, and it works fine so far.
This all seems to be working great for me using jimp until the part where I try to set it to the object in the beforeSave hook. I see the images showing up in S3 and it comes back correctly. I have other attributes that are getting set correctly as well. It is just the 'pictureThumbnail' that isn't. For some reason it just seems as if it's not updating the request.object. @rickkrauland Was there something you had to do different then what is documented in @nitrag 's example?
Activity
christianmarth commentedon Feb 25, 2016
Have a look at
https://github.com/hacksparrow/node-easyimage
or
https://github.com/yourdeveloper/node-imagemagick
oyvindvol commentedon Feb 25, 2016
@christianmarth Thanks! E.g. in the first link example (EasyImage), how would you initialize an image from the response.buffer like I do in line 8 of my pasted code?
flovilmart commentedon Feb 25, 2016
@oyvindvol I wrote a wrapper for Parse.Image that has 100% compatibility with the original parse-image:
https://github.com/flovilmart/parse-image.
nitrag commentedon Feb 25, 2016
I was just getting to the point where I needed this too. Thanks @flovilmart !
flovilmart commentedon Feb 25, 2016
@nitrag @oyvindvol the installation is automated on debian and OSX. Installation in Windows is not working yet. For heroku, you need to add a build pack (as explained in the README)
oyvindvol commentedon Feb 25, 2016
@flovilmart Nice! So, to use this on a heroku based install of parse-server, i just add imagemagick , graphicsmagick and your parse-image to my package.json, and add
var Image = require("parse-image")to the top of my cloud code file?flovilmart commentedon Feb 25, 2016
@oyvindvol follow the instructions here: https://github.com/flovilmart/parse-image#heroku-installation
then:
Given the code you provided, it seems that it should work right away.
oyvindvol commentedon Feb 25, 2016
@flovilmart Ok, so now I did only the "Heroku installation" part, and after deploy the heroku logs say "Cannot find module 'parse-image'". Then I added 'parse-image' as a dependency in package.json, and I still get "cannot find module 'parse-image'" in the logs.
flovilmart commentedon Feb 25, 2016
Did you run
npm install --save parse-image?oyvindvol commentedon Feb 25, 2016
@flovilmart On Heroku server?
flovilmart commentedon Feb 25, 2016
does it work locally with foreman?
oyvindvol commentedon Feb 25, 2016
I haven`t tested locally, I am just trying to set it up on my parse-server-example that I deployed directly to Heroku. I configured the heroku-buildpack-graphicsmagick via git bash, and push to heroku master. I can see that the buildpack is installed, but am I also supposed to put something in my package.json for it to work in my cloud code?
flovilmart commentedon Feb 25, 2016
the build pack is installing the binaries required to parse-image to work correctly.
When you push to heroku, you you see parse-image being installed? Can you give me the heroku logs?
oyvindvol commentedon Feb 25, 2016
Ok, starting from fresh. I added the buildpack in git bash. I remove everything regarding parse-image from my package.json, then i do
git push heroku master. This shows in the console:After deploy finished, this is the heroku logs:
flovilmart commentedon Feb 25, 2016
it seems that your package.json is not properly updated, or that heroku don't like it..
Try to run on your machine:
npm install --save parse-imageand then deploy to heroku8 remaining items
oyvindvol commentedon Feb 25, 2016
Well, initially this issue was about using the recommended Imagemagick in parse server cloud code. I am still interested in examples on that though..
flovilmart commentedon Feb 25, 2016
OK, can you post an issue on parse-image I'll re-open in that case.
flovilmart commentedon Feb 25, 2016
http://stackoverflow.com/questions/30309633/after-replacing-rmagick-with-minimagick-gets-identify-im6-no-decode-delegate
simonbengtsson commentedon Feb 25, 2016
I used jimp to replace
parse-imagewhen I migrated our app. It is written entirely in JavaScript for Node so no external dependencies needed (no special install on heroku or windows). It probably has worse performance than imagemagick, but I have yet to run any benchmarks. We are scaling a lot of images in our app however and so far it looks promising.oyvindvol commentedon Feb 26, 2016
@simonbengtsson That looks lightweight and good. Are you using jimp to e.g. save thumbnails via cloud code? I am having trouble getting that work. With the code provided below, everything seems OK, and the thumb is saved on the "Message" object, but viewing the thumb in the browser with the file URL is not working.
simonbengtsson commentedon Feb 26, 2016
Yes we are generating thumbnails in cloud code using jimp. Your issue is probably that the string from
image.hash()cannot be used as data for parse files. Try something like this instead:oyvindvol commentedon Feb 29, 2016
@simonbengtsson Thanks! :) That worked..
nitrag commentedon Mar 3, 2016
Since it took me several hours to get this correct I'm posting here so the next guy has an easier time:
6thfdwp commentedon May 14, 2016
Thanks for sharing this pure js image module, here is the benchmarks I found for jimp in comparison with other libraries.
lovell/sharp#275 (comment)
It seems enough for common image processing cases.
majidhassan commentedon May 29, 2016
@flovilmart I tried your parse-image module on Heroku for a simple thumbnail generation. I did not need to change a single line of code, only added "parse-image": "~0.1.1" in my package.json dependencies, and it works fine so far.
Great job!
rickkrauland commentedon Aug 7, 2016
@nitrag Thanks for your post. Fwiw, I had to add a buffer.toString conversion before I could get everything to work.
parkej60 commentedon Sep 23, 2016
This all seems to be working great for me using jimp until the part where I try to set it to the object in the beforeSave hook. I see the images showing up in S3 and it comes back correctly. I have other attributes that are getting set correctly as well. It is just the 'pictureThumbnail' that isn't. For some reason it just seems as if it's not updating the request.object. @rickkrauland Was there something you had to do different then what is documented in @nitrag 's example?
parkej60 commentedon Sep 23, 2016
So... turns out that response.success doesn't want a string sent along with it. I removed "thumbnail saved" from response.success() and it worked.