Skip to content

Commit

Permalink
when transforming asset, adjust width and hight too
Browse files Browse the repository at this point in the history
  • Loading branch information
i-just committed Feb 13, 2024
1 parent 62610a7 commit 3767558
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
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 3767558

Please sign in to comment.