fix: properly never upscale
This commit is contained in:
parent
db0c862440
commit
dc21d085ec
2 changed files with 31 additions and 11 deletions
|
@ -243,34 +243,54 @@ export const baseService: Omit<LocalImageService, 'transform'> = {
|
|||
|
||||
densityWidths.forEach((width, index) => {
|
||||
const maxTargetWidth = Math.min(width, maxWidth);
|
||||
srcSet.push({
|
||||
|
||||
const srcSetValue = {
|
||||
transform: {
|
||||
...options,
|
||||
width: maxTargetWidth,
|
||||
height: Math.round(maxTargetWidth / aspectRatio),
|
||||
format: targetFormat,
|
||||
},
|
||||
descriptor: `${densityValues[index]}x`,
|
||||
attributes: {
|
||||
type: `image/${targetFormat}`,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// Only set width and height if they are different from the original image
|
||||
if (maxTargetWidth !== imageWidth) {
|
||||
srcSetValue.transform.width = maxTargetWidth;
|
||||
srcSetValue.transform.height = Math.round(maxTargetWidth / aspectRatio);
|
||||
}
|
||||
|
||||
if (targetFormat !== options.format) {
|
||||
srcSetValue.transform.format = targetFormat;
|
||||
}
|
||||
|
||||
srcSet.push();
|
||||
});
|
||||
} else if (widths) {
|
||||
widths.forEach((width) => {
|
||||
const maxTargetWidth = Math.min(width, maxWidth);
|
||||
srcSet.push({
|
||||
|
||||
const srcSetValue = {
|
||||
transform: {
|
||||
...options,
|
||||
width,
|
||||
height: Math.round(maxTargetWidth / aspectRatio),
|
||||
format: targetFormat,
|
||||
},
|
||||
descriptor: `${width}w`,
|
||||
attributes: {
|
||||
type: `image/${targetFormat}`,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// Only set width and height if they are different from the original image
|
||||
if (maxTargetWidth !== imageWidth) {
|
||||
srcSetValue.transform.width = maxTargetWidth;
|
||||
srcSetValue.transform.height = Math.round(maxTargetWidth / aspectRatio);
|
||||
}
|
||||
|
||||
if (targetFormat !== options.format) {
|
||||
srcSetValue.transform.format = targetFormat;
|
||||
}
|
||||
|
||||
srcSet.push(srcSetValue);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ export function propsToFilename(transform: ImageTransform, hash: string) {
|
|||
|
||||
export function hashTransform(transform: ImageTransform, imageService: string) {
|
||||
// Extract the fields we want to hash
|
||||
const { alt, class: className, style, ...rest } = transform;
|
||||
const { alt, class: className, style, widths, densities, ...rest } = transform;
|
||||
const hashFields = { ...rest, imageService };
|
||||
return shorthash(JSON.stringify(hashFields));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue