Skip to content

Commit

Permalink
Merge pull request #66 from HarmenM/master
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
HarmenM authored May 1, 2019
2 parents 2a4febc + 0be9cd3 commit 8585ce3
Show file tree
Hide file tree
Showing 5 changed files with 512 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/lib/extractors/AbstractStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const imageType = require('image-type');
const isSvg = require('is-svg');
const icoToPng = require('ico-to-png');
const hasha = require('hasha');
const sharp = require('sharp');

class AbstractStrategy
{
Expand Down Expand Up @@ -56,6 +57,10 @@ class AbstractStrategy
case "gif":
result.extension = imageInfo.ext;
break;
case "webp":
result.buffer = await sharp(result.buffer).png().toBuffer();
result.extension = "png";
break;
case"ico":
let pngBuffer = await this.parseIco(result.buffer, src);

Expand Down
33 changes: 31 additions & 2 deletions app/lib/extractors/dom-logo/DOMLogoStrategyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class DOMLogoStrategyParser {

} else if (element.tagName.toLowerCase() === "object" && element.getAttribute("type")) { // Image in object
logos = [...logos, ...this.parseImageObject(element)];

} else if (this.hasLogoClass(element)) {

// Check if the current element not only has a logo class, but has an image as background
Expand Down Expand Up @@ -311,10 +312,10 @@ class DOMLogoStrategyParser {
);
}
}
} else if (src.match(/^data:image\/(?:png|jpg|gif);base64,/i)) {
} else if (src.match(/^data:image\/(?:png|jpg|gif|webp);base64,/i)) {
logos.push(
this.createLogoMatch(
{type: 'base64', src: src},
{type: 'file', src: src},
element,
.2
)
Expand All @@ -341,6 +342,20 @@ class DOMLogoStrategyParser {
}
}

let containedImages = element.querySelectorAll(":scope > image[*|href]");

if(containedImages.length > 0) {
let logos = [];

containedImages.forEach((image) => logos = [...logos, ...this.parseSVGImage(image, element)]);

return logos;
} else {
return this.parseInlineSVG(element);
}
}

parseInlineSVG(element) {
let boundingClientRect = element.getBoundingClientRect();
let marker = "svg-mark-for-download-" + DOMLogoStrategyParser.inlineSvgMarker++;

Expand All @@ -357,6 +372,20 @@ class DOMLogoStrategyParser {
)];
}

parseSVGImage(imageElement, hostElement) {
let src = imageElement.getAttribute("xlink:href") || imageElement.getAttribute("href");

if(src) {
return [this.createLogoMatch(
{type: 'file', src: this.convertUrlToAbsolute(src)},
hostElement,
.2
)];
} else {
return [];
}
}

parseImageObject(element) {
let type = element.getAttribute("type");
let acceptedTypes = ["image/svg+xml", "image/png"];
Expand Down
4 changes: 4 additions & 0 deletions app/lib/extractors/dom-logo/DomLogoStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class DomLogoStrategy extends AbstractStrategy
if(imageDefinition) {
let weight = this.weighLogo(logo, imageDefinition);

// if(imageDefinition.origin === "https://www.pearle.nl/is-bin/intershop.static/WFS/org-nl_pearle-Site/-/nl_NL/images/branding.png") {
console.log(imageDefinition.origin, weight);
// }

images.push({
buffer: imageDefinition.buffer,
hash: this.getBufferHash(imageDefinition.buffer),
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"nan": "^2.13.2",
"node-fetch": "^2.3.0",
"node-vibrant": "^3.2.0-alpha",
"sharp": "^0.22.1",
"urijs": "^1.19.0"
}
}
Loading

0 comments on commit 8585ce3

Please sign in to comment.