How to use svg-autocrop - 1 common examples

To help you get started, we’ve selected a few svg-autocrop examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cncf / landscapeapp / tools / fetchImages.js View on Github external
if (url.indexOf('http://') !== 0 && url.indexOf('https://') !== 0) {
        if (fs.readdirSync(path.resolve(projectPath, 'hosted_logos')).indexOf(url) === -1) {
          throw new Error(`there is no file ${url} in a hosted_logos folder`);
        }
        response = fs.readFileSync(path.resolve(projectPath, 'hosted_logos', url));
      } else {
        response = await rp({
          encoding: null,
          uri: url,
          followRedirect: true,
          maxRedirects: 5,
          simple: true,
          timeout: 30 * 1000
        });
      }
      const croppedSvgResult = await autoCropSvg(response, {title: `${item.name} logo`});
      const croppedSvg = croppedSvgResult.result;
      require('fs').writeFileSync(path.resolve(projectPath, `cached_logos/${fileName}`), croppedSvg);
      reporter.write(cacheMiss('*'));
      return {
        fileName: fileName,
        name: item.name,
        logo: item.logo,
        hash: hash
      };
    } catch(ex) {
      debug(`Cannot fetch ${url}`);
      const message = ex.message || ex || 'Unknown error';
      if (cachedEntry && imageExist(cachedEntry)) {
        addWarning('image');
        reporter.write(error('E'));
        errors.push(error(`Using cached entry, because ${item.name} has issues with logo: ${url}, ${message}`));

svg-autocrop

Auto crop svg files and remove extraneous tags and attributes

Apache-2.0
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis

Popular svg-autocrop functions