Skip to content

Commit

Permalink
Merge pull request #165 from craftcms/bugfix/94-transformimagecommand…
Browse files Browse the repository at this point in the history
…-adjust-dimensions

when transforming asset, adjust width and hight too
  • Loading branch information
brandonkelly authored Feb 21, 2024
2 parents 62610a7 + a57f120 commit 73278e6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for CKEditor for Craft CMS

## Unreleased

- Fixed a bug where resized images weren’t getting updated `width` and `height` attributes. ([#165](https://github.com/craftcms/ckeditor/pull/165))

## 3.7.3 - 2024-02-08

- Fixed a JavaScript error. ([#161](https://github.com/craftcms/ckeditor/issues/161))
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/CkeditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function actionImageUrl(): Response

return $this->asJson([
'url' => $asset->getUrl($transform, false),
'width' => $asset->getWidth($transform),
'height' => $asset->getHeight($transform),
]);
}
}
2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/ckeditor/dist/ckeditor5-craftcms.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ export default class TransformImageCommand extends Command {
model.change((writer) => {
const src = data.url + hash;
writer.setAttribute('src', src, element);

// update image width and height to match the transformed size;
// ckeditor insists on keeping those around:
// https://ckeditor.com/docs/ckeditor5/latest/features/images/images-overview.html#image-width-and-height-attributes
if (data.width) {
writer.setAttribute('width', data.width, element);
}
if (data.height) {
writer.setAttribute('height', data.height, element);
}
});
});
}
Expand Down

0 comments on commit 73278e6

Please sign in to comment.