Closed
Description
Hi,
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);
});
});
Any help will be much appreciated!
Metadata
Metadata
Assignees
Labels
No labels