Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* sizes can be the string 'any' OR
* space seperated list of
* two non-negative integers without leading 0s and separated by 'x' like 144x144
*/
if (iconSizes === 'any') {
return false;
}
// Working on local environment so no access to the real image for further checking
if (!iconRawData) {
return true;
}
const specifiedSizes = iconSizes.split(' ');
const realImage = getImageData(iconRawData);
/**
* Do not report if one of the specified size match real icon size
*/
const sizesMatch = specifiedSizes.some((specifiedSize) => {
const [widthString, heightString] = specifiedSize.split('x');
const specifiedWidth = parseInt(widthString);
const specifiedHeight = parseInt(heightString);
return specifiedWidth === realImage.width && specifiedHeight === realImage.height;
});
if (!sizesMatch && realImage.width && realImage.height) {
const message = getMessage('realImageSizeNotMatch', context.language, [realImage.width.toString(), realImage.height.toString(), specifiedSizes.toString()]);
context.report(
'0',
'--output',
tracedPath,
thresholdedAlphaPath,
);
// Parse the traced PostScript file and convert it to a JSON file containing all shapes
const shapesPath = this.getTempPath(inputPath, 'shapes.json');
this.info(`Converting ${tracedPath} to shape paths`);
const shapes = await postScriptToShapes(tracedPath, shapesPath, tolerance);
// Convert the shape data into triangle data
this.info(`Converting shape paths to triangulated shapes`);
const triangles = await shapesToTriangulatedShapes(shapes);
const inputDimensions = await imageSize(inputPath);
const data: any = {
width: inputDimensions.width,
height: inputDimensions.height,
shapes: triangles,
};
if (this.flags.path) {
const paths: Point[][] = [];
for (const shape of shapes) {
const currentPath: Point[] = [];
if (shape.mainPath !== null) {
for (const point of shape.mainPath) {
currentPath.push({
const analyzeImage = (fetchEnd: FetchEnd) => {
if (!configured) {
return;
}
const { response } = fetchEnd;
try {
// TODO: Find a better way than doing this to detect if it's an image
getImageData(response.body.rawContent);
uploads.push(processImage(fetchEnd));
} catch (e) {
if (e instanceof TypeError) {
// Not an image, ignoring
}
}
};
/*
* Notes:
*
* * Async version of `image-size` doesn't work if the
* input is a Buffer.
*
* https://github.com/image-size/image-size/tree/4c527ba608d742fbb29f6d9b3c77b831b069cbb2#asynchronous
*
* * `image-size` will throw a `TypeError` error if it does
* not understand the file type or the image is invalid
* or corrupted.
*/
try {
image = getImageData(response.body.rawContent);
} catch (e) {
if (e instanceof TypeError) {
const message = getMessage('invalidPNG', context.language, appleTouchIconHref);
context.report(
resource,
message,
{ element: appleTouchIcon, severity: Severity.error }
);
} else {
debug(`'getImageData' failed for '${appleTouchIconURL}'`);
}
return;
}