Skip to content

Commit

Permalink
#6 Limit asset thumbnail size to 2048 pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel van Hintum committed Jul 5, 2021
1 parent b953fa1 commit 2134dbc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/templates/_components/field/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@
{% endif %}
</div>

{% set width = 0 %}
{% set height = 0 %}

{% if asset is not null %}
{% set maxSize = min(2048, asset.width, asset.height) %}
{% set ratioW = asset.width / asset.height %}
{% set ratioH = asset.height / asset.width %}

{% set width = (ratioW > ratioH) ? maxSize : maxSize * ratioW %}
{% set height = (ratioH > ratioW) ? maxSize : maxSize * ratioH %}
{% endif %}

{% set jsSettings = {
id: id|namespaceInputId,
asset: (asset is not null) ? {
url: craft.app.assets.thumbUrl(asset, asset.width, asset.height, false, false),
url: craft.app.assets.thumbUrl(asset, width, height, false, false),
width: asset.width,
height: asset.height,
} : null,
Expand Down

0 comments on commit 2134dbc

Please sign in to comment.