Skip to content

Commit

Permalink
use svg autocrop module, close #15 (#87)
Browse files Browse the repository at this point in the history
* use our npm package

* removing extra checks

* one more update

* upgrade svg autocrop version

* using a latest svg-autocrop version

* update to the latest version
  • Loading branch information
AndreyKozlov1984 authored and dankohn committed Jan 18, 2019
1 parent 310469f commit 601b726
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 306 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"connect": "3.6.6",
"connect-history-api-fallback": "1.5.0",
"connected-react-router": "6.1.0",
"convert-svg-to-png": "0.5.0",
"css-loader": "2.0.2",
"cssnano": "4.1.8",
"current-device": "0.7.8",
Expand All @@ -114,7 +113,6 @@
"iframe-resizer": "3.6.3",
"jest": "23.6.0",
"jest-cli": "23.6.0",
"jimp": "^0.2.28",
"js-yaml": "3.12.0",
"jsdom": "13.1.0",
"json-loader": "0.5.7",
Expand Down Expand Up @@ -159,6 +157,7 @@
"sitemap": "2.1.0",
"string-replace-all": "1.0.3",
"style-loader": "0.23.1",
"svg-autocrop": "1.0.10",
"terser-webpack-plugin": "1.2.0",
"traverse": "0.6.6",
"twitter": "1.7.1",
Expand All @@ -171,7 +170,6 @@
"webpack-hot-middleware": "2.24.3",
"webpack-md5-hash": "0.0.6",
"why-did-you-update": "1.0.6",
"xml2js": "0.4.19",
"yahoo-finance": "0.3.5",
"yaml-loader": "0.5.0"
},
Expand Down
5 changes: 2 additions & 3 deletions tools/fetchImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path';
import _ from 'lodash';
import { settings, projectPath } from './settings';
import { addError, addWarning } from './reporter';
import { ensureViewBoxExists, autoCropSvg } from './processSvg';
import autoCropSvg from 'svg-autocrop';
const debug = require('debug')('images');

const error = colors.red;
Expand Down Expand Up @@ -127,8 +127,7 @@ export async function fetchImageEntries({cache, preferCache}) {
timeout: 30 * 1000
});
}
const processedSvg = await ensureViewBoxExists(response);
const croppedSvg = await autoCropSvg(processedSvg);
const croppedSvg = await autoCropSvg(response, {title: item.name});
require('fs').writeFileSync(path.resolve(projectPath, `cached_logos/${fileName}`), croppedSvg);
require('process').stdout.write(cacheMiss("*"));
return {
Expand Down
21 changes: 0 additions & 21 deletions tools/generateJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,27 +345,6 @@ if(hasBadImages) {
require('process').exit(-1);
}

var hasBadSvgImages = false;
_.each(itemsWithExtraFields, function(item) {
const imageFileName = `${projectPath}/cached_logos/` + item.image_data.fileName;
const content = require('fs').readFileSync(imageFileName, 'utf-8');
if (content.indexOf('base64,') !== -1) {
hasBadSvgImages = true;
console.info(`FATAL ERROR: Item ${item.name} has a file ${imageFileName} which embeds a png. Please use a pure svg file`);
}
if (content.indexOf('<text') !== -1) {
hasBadSvgImages = true;
console.info(`FATAL ERROR: Item ${item.name} has a file ${imageFileName} which has a <text> element. Please convert it to the glyph first, because we can not render it the same way on all computers, especially on our render server`);
}
if (content.indexOf('<tspan') !== -1) {
hasBadSvgImages = true;
console.info(`FATAL ERROR: Item ${item.name} has a file ${imageFileName} which has a <tspan> element. Please convert it to the glyph first, because we can not render it the same way on all computers, especially on our render server`);
}
});
if(hasBadSvgImages) {
require('process').exit(-1);
}


function removeNonReferencedImages() {
const fs = require('fs');
Expand Down
93 changes: 0 additions & 93 deletions tools/processSingleImage.js

This file was deleted.

183 changes: 0 additions & 183 deletions tools/processSvg.js

This file was deleted.

0 comments on commit 601b726

Please sign in to comment.