mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
eef7932e94
refs #8868 - Removed image-size in blog logo fn for meta data and made it synchronous - Renamed `image-size-from-url.js` to `image-size.js` (incl. the test) - Added second fn `getImageSizeFromFilePath` that reads from local file storage - Added guard in `getImageSizeFromUrl` that checks if the image should be on local file storage and uses the new fn then instead - Added a fn `fetchDimensionsFromBuffer` that takes the file buffer and returns an `imageObject` with dimensions. - Added a new utils.js in `adapters/storage` for getting the file storage path
68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
var getCachedImageSizeFromUrl = require('../../utils/cached-image-size-from-url'),
|
|
Promise = require('bluebird'),
|
|
_ = require('lodash');
|
|
|
|
/**
|
|
* Get Image dimensions
|
|
* @param {object} metaData
|
|
* @returns {object} metaData
|
|
* @description for image properties in meta data (coverImage, authorImage and blog.logo), `getCachedImageSizeFromUrl` is
|
|
* called to receive image width and height
|
|
*/
|
|
function getImageDimensions(metaData) {
|
|
var fetch = {
|
|
coverImage: getCachedImageSizeFromUrl(metaData.coverImage.url),
|
|
authorImage: getCachedImageSizeFromUrl(metaData.authorImage.url),
|
|
ogImage: getCachedImageSizeFromUrl(metaData.ogImage.url),
|
|
logo: getCachedImageSizeFromUrl(metaData.blog.logo.url)
|
|
};
|
|
|
|
return Promise.props(fetch).then(function (resolve) {
|
|
var imageObj = {};
|
|
|
|
imageObj = {
|
|
coverImage: resolve.coverImage,
|
|
authorImage: resolve.authorImage,
|
|
ogImage: resolve.ogImage,
|
|
logo: resolve.logo
|
|
};
|
|
|
|
_.forEach(imageObj, function (key, value) {
|
|
if (_.has(key, 'width') && _.has(key, 'height')) {
|
|
// We have some restrictions for publisher.logo:
|
|
// The image needs to be <=600px wide and <=60px high (ideally exactly 600px x 60px).
|
|
// Unless we have proper image-handling (see https://github.com/TryGhost/Ghost/issues/4453),
|
|
// we will fake it in some cases or not produce an imageObject at all.
|
|
if (value === 'logo') {
|
|
if (key.height <= 60 && key.width <= 600) {
|
|
_.assign(metaData.blog[value], {
|
|
dimensions: {
|
|
width: key.width,
|
|
height: key.height
|
|
}
|
|
});
|
|
} else if (key.width === key.height) {
|
|
// CASE: the logo is too large, but it is a square. We fake it...
|
|
_.assign(metaData.blog[value], {
|
|
dimensions: {
|
|
width: 60,
|
|
height: 60
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
_.assign(metaData[value], {
|
|
dimensions: {
|
|
width: key.width,
|
|
height: key.height
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
return metaData;
|
|
});
|
|
}
|
|
|
|
module.exports = getImageDimensions;
|