Skip to content

Commit

Permalink
Merge pull request #145 from wrboyce/main
Browse files Browse the repository at this point in the history
disable adding svg height/width attrs by default, add option
  • Loading branch information
georges-gomes authored Mar 26, 2024
2 parents 73e6479 + fe12e4b commit 032d492
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const default_options: Options = {
},
svg: {
optimization: true,
add_width_and_height: false,
},
},
misc: {
Expand Down
1 change: 1 addition & 0 deletions src/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export type Options = {
};
svg: {
optimization: boolean;
add_width_and_height: boolean;
};
};
misc: {
Expand Down
7 changes: 6 additions & 1 deletion src/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,11 @@ async function setImageSize(
let height = img.attr('height');
let width_new: number | undefined = undefined;
let height_new: number | undefined = undefined;
const img_fmt = await image.getExt();

if (img_fmt === 'svg' && !config.image.svg.add_width_and_height) {
return [];
}

// Check valid values
if (width !== undefined) {
Expand Down Expand Up @@ -893,7 +898,7 @@ async function setImageSize(
} else {
// No width or height provided - set both to image size

if ((await image.getExt()) === 'svg') {
if (img_fmt === 'svg') {
// svg with no height and width has special sizing by browsers
// They size it inside 300x150 unless they have width and height
// attributes
Expand Down

0 comments on commit 032d492

Please sign in to comment.