').attr('src','https://static.squarespace.com/static/592f0812414fb54f04562d89/t/5bd0bbbe08522953060e994d/1540406206485/getImageDataURI.html?img='+encodeURIComponent(images.join('img='))).appendTo('.image-detection-container') } if (static1_assets.length > 0) { static1_assets.forEach(function(o){ picsToTest[o.assetUrl]=1 }); var images1 = static1_assets.reduce(function(a,o){ return a.concat(o.assetUrl); }, []); $('').attr('src','https://static1.squarespace.com/static/592f0812414fb54f04562d89/t/5bd0bbbe08522953060e994d/1540406206485/getImageDataURI.html?img='+encodeURIComponent(images1.join('img='))).appendTo('.image-detection-container') } if (static2_assets.length > 0) { static2_assets.forEach(function(o){ picsToTest[o.assetUrl]=1 }); var images2 = static2_assets.reduce(function(a,o){ return a.concat(o.assetUrl); }, []); $('').attr('src','https://static2.squarespace.com/static/592f0812414fb54f04562d89/t/5bd0bbbe08522953060e994d/1540406206485/getImageDataURI.html?img='+encodeURIComponent(images2.join('img='))).appendTo('.image-detection-container') } } else { if (data === undefined){ setTimeout(getLoadedBGImages, 1000); } } } // ----------------------------------------------------------------------------------------------------------- function receiveMessage(evt){ if (evt.origin !== 'https://static.squarespace.com' && evt.origin !== 'https://static1.squarespace.com' && evt.origin !== 'https://static2.squarespace.com'){ return; } var data = evt.data; if (data.error) { picsToTest[data.imgUrl] = undefined; delete picsToTest[data.imgUrl]; if (Object.keys(picsToTest).length === 0) { testingDone(); } return } var $canvas = $('').attr({ width: data.width, height: data.height }).css({ width: data.width, height: data.height, }).appendTo($('.image-detection-container')); var img = new Image(); img.width = data.width; img.height = data.height; img.src = data.imgdata; img.onload = function(){ var ctx = $canvas[0].getContext('2d'); ctx.drawImage(img, 0, 0, data.width, data.height) var imgData = ctx.getImageData(0, 0, data.width, data.height).data; var pix = getPixel(11, 11, imgData, data.width); var isUnique = true; for (var key in samePics){ if (Math.abs(samePics[key].r - pix.r) < 3 && Math.abs(samePics[key].g - pix.g) < 3 && Math.abs(samePics[key].b - pix.b) < 3 && Math.abs(samePics[key].a - pix.a) < 3 ) { isUnique = false; break; } } if (isUnique === true) { samePics[data.imgUrl] = pix; } picsToTest[data.imgUrl] = undefined; delete picsToTest[data.imgUrl]; if (Object.keys(picsToTest).length === 0) { testingDone(); } } } //-------------------------------------------------------------------------------------------- function getPixel(x,y,data, width){ return { r: data[(x*4)+(y*width)], g: data[(x*4)+(y*width)+1], b: data[(x*4)+(y*width)+2], a: data[(x*4)+(y*width)+3] } } //-------------------------------------------------------------------------------------------- function testingDone(){ var uniqueImages = Object.keys(samePics); $('.lead-form-images').addClass('imagecount-' + Math.min(uniqueImages.length, 4)); for (var img=0;img<4;img++){ if ($('.image-blocks').find('.block-'+(img+1)).data('src') === undefined && uniqueImages[img]) { var focalPoint = assets.reduce(function(a,o){ if (uniqueImages[img] === o.assetUrl){ return o.mediaFocalPoint } else { return a; } },{x:0.5,y:0.5}); if (img === 0 && uniqueImages[img].indexOf('squarespace.com/static') !==-1 && uniqueImages[img].indexOf('format=500w') !== -1) { uniqueImages[img] = uniqueImages[img].replace('format=500w', 'format=1024w') } $('.image-blocks').find('.block-'+(img+1)).css({ 'backgroundImage': 'url('+uniqueImages[img]+')', 'backgroundPosition': 'calc('+focalPoint.x+' * 100%) calc('+focalPoint.y+' * 100%)' }).data('src',uniqueImages[img]); } } } //-------------------------------------------------------------------------------------------- window.addEventListener( "message", receiveMessage, false); $('.lead-form-lightbox form').append($('')); $('.lead-form-lightbox form').append($('')); //------------------------------------------------------------------------------------------------------ })();


Upload Background Image:
Custom Background Brightness:
Upload Background Image: