Last active
August 29, 2015 14:22
-
-
Save nicolaslopezj/3d887bca830ba1d523b7 to your computer and use it in GitHub Desktop.
File Attribute -> Image Attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var info = function(image) { | |
var colorInfo = Colibri.extractImageColors(image, 'hex'); | |
var width = image.naturalWidth; | |
var height = image.naturalHeight; | |
console.log(colorInfo); | |
return { | |
width: width, | |
height: height, | |
backgroundColor: colorInfo.background, | |
primaryColor: colorInfo.content[0], | |
secondaryColor: colorInfo.content[1] || colorInfo.content[0], | |
} | |
} | |
var sub = Meteor.subscribe('allProducts'); | |
Tracker.autorun(function () { | |
if (sub.ready()) { | |
Tracker.nonreactive(function () { | |
var total = 0; | |
var count = 0; | |
Products.find().forEach(function (product) { | |
var imageUrl = product.image.url; | |
var imageUrl = imageUrl.replace('https://s3.amazonaws.com/decomarias/orionjs', 'https://decomarias.s3.amazonaws.com/orionjs') | |
if (imageUrl) { | |
total++; | |
var img = new Image(); | |
img.crossOrigin = 'Anonymous'; | |
img.onload = function(){ | |
var imageInfo = info(img); | |
Products.update(product._id, { $set: { 'image.info': imageInfo } }) | |
count++; | |
console.log(imageInfo, count + '/' + total); | |
}; | |
img.src = imageUrl; | |
} | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment