-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using blurhash for obscuring sensitive image (#342)
replaced blur filter usage over sensitive image to obscure the image with blurhash image, using hidden checkbox + css to control visibility and buttons to switch between show and hide sensitive image for image attachment in post and comments, hide the sensitive image by putting blurhash image over along with the show button for entry thumbnail, it works a bit differently: - the sensitive image is hidden by hiding the main image and show existing blurhash background image instead - due to space constraints, the show/hide button is icons only, additionally when in mobile layout and compact view, the hide button will not be shown after the image is revealed
- Loading branch information
Showing
13 changed files
with
255 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// main wrapper | ||
.figure-container { | ||
position: relative; | ||
width: fit-content; | ||
height: fit-content; | ||
} | ||
|
||
// main image thumbnail | ||
.figure-thumb { | ||
.thumb { | ||
display: block; | ||
} | ||
|
||
img { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
} | ||
|
||
// blurhash image obscuring main image | ||
.figure-blur { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
|
||
img { | ||
width: 100%; | ||
height: 100%; | ||
overflow: hidden; | ||
object-fit: cover; | ||
} | ||
} | ||
|
||
// checkbox to store sensitive state | ||
input.sensitive-state { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 0; | ||
height: 0; | ||
opacity: 0; | ||
} | ||
|
||
// button to toggle sensitive | ||
.sensitive-button { | ||
position: absolute; | ||
|
||
&-label { | ||
background: var(--kbin-button-secondary-bg); | ||
padding: .5rem; | ||
|
||
font-weight: normal; | ||
font-size: .8rem; | ||
text-align: center; | ||
|
||
opacity: .8; | ||
|
||
i { | ||
font-size: 1rem; | ||
} | ||
|
||
.rounded-edges & { | ||
border-radius: var(--kbin-rounded-edges-radius); | ||
} | ||
|
||
&:hover, | ||
&:active { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
&-show { | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
|
||
.sensitive-button-label { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%,-50%); | ||
} | ||
} | ||
|
||
&-hide { | ||
top: .5rem; | ||
right: .5rem; | ||
|
||
.sensitive-button-label { | ||
opacity: .5; | ||
line-height: 1rem; | ||
|
||
i { | ||
font-size: .9rem; | ||
} | ||
|
||
&:hover, | ||
&:active { | ||
opacity: .7; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// the magic part: toggle visibility depending on sensitive state | ||
.sensitive-state { | ||
~ .sensitive-checked--hide { | ||
display: initial; | ||
} | ||
|
||
~ .sensitive-checked--show { | ||
display: none; | ||
} | ||
} | ||
|
||
.sensitive-state:checked { | ||
~ .sensitive-checked--hide { | ||
display: none; | ||
} | ||
|
||
~ .sensitive-checked--show { | ||
display: revert; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{# this fragment is only meant to be used in entry component #} | ||
{% with { | ||
sensitiveId: 'sensitive-check-'~entry.image.id, | ||
isSingle: is_route_name('entry_single'), | ||
route: isSingle ? singleRoute : entry_url(entry) | ||
} %} | ||
<figure> | ||
<div class="image-filler" aria-hidden="true"> | ||
{% if entry.image.blurhash %} | ||
{{ component('blurhash_image', {blurhash: entry.image.blurhash}) }} | ||
{% endif %} | ||
</div> | ||
{% if entry.isAdult %} | ||
<input id="{{ sensitiveId }}" | ||
type="checkbox" | ||
class="sensitive-state" | ||
aria-label="{{ 'sensitive_toggle'|trans }}"> | ||
{% endif %} | ||
<a href="{{ route }}" | ||
class="{{ html_classes('sensitive-checked--show', {'thumb': isSingle and lightbox|default(false)}) }}" | ||
rel="{{ setRel ? get_rel(route) : '' }}" | ||
> | ||
<img class="thumb-subject" | ||
src="{{ asset(entry.image.filePath)|imagine_filter('entry_thumb') }}" | ||
alt="{{ entry.image.altText }}"> | ||
</a> | ||
{% if entry.isAdult %} | ||
<label for="{{ sensitiveId }}" | ||
class="sensitive-button sensitive-button-show sensitive-checked--hide" | ||
title="{{ 'sensitive_show'|trans }}" | ||
aria-label="{{ 'sensitive_show'|trans }}"> | ||
<div class="sensitive-button-label"> | ||
<i class="fa-solid fa-eye"></i> | ||
</div> | ||
</label> | ||
<label for="{{ sensitiveId }}" | ||
class="sensitive-button sensitive-button-hide sensitive-checked--show" | ||
title="{{ 'sensitive_hide'|trans }}" | ||
aria-label="{{ 'sensitive_hide'|trans }}"> | ||
<div class="sensitive-button-label"> | ||
<i class="fa-solid fa-eye-slash"></i> | ||
</div> | ||
</label> | ||
{% endif %} | ||
</figure> | ||
{% endwith %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<figure> | ||
<div class="figure-container"> | ||
<div class="figure-thumb"> | ||
<a href="{{ uploaded_asset(image.filePath) }}" class="thumb"> | ||
<img src="{{ asset(image.filePath)|imagine_filter(thumbFilter) }}" | ||
alt="{{ image.altText }}"> | ||
</a> | ||
</div> | ||
{% if isAdult %} | ||
{% with {sensitiveId: 'sensitive-check-'~image.id} %} | ||
<input id="{{ sensitiveId }}" | ||
type="checkbox" | ||
class="sensitive-state" | ||
aria-label="{{ 'sensitive_toggle'|trans }}"> | ||
<label for="{{ sensitiveId }}" | ||
class="sensitive-button sensitive-button-show sensitive-checked--hide" | ||
title="{{ 'sensitive_show'|trans }}"> | ||
<div class="figure-blur" aria-hidden="true"> | ||
{{ component('blurhash_image', {blurhash: image.blurhash, width: 32, height: 32}) }} | ||
</div> | ||
<div class="sensitive-button-label"> | ||
{{ 'sensitive_warning'|trans }} <br> | ||
{{ 'sensitive_show'|trans }} | ||
</div> | ||
</label> | ||
<label for="{{ sensitiveId }}" | ||
class="sensitive-button sensitive-button-hide sensitive-checked--show" | ||
title="{{ 'sensitive_hide'|trans }}" | ||
aria-label="{{ 'sensitive_hide'|trans }}"> | ||
<div class="sensitive-button-label" > | ||
<i class="fa-solid fa-eye-slash"></i> | ||
</div> | ||
</label> | ||
{% endwith %} | ||
{% endif %} | ||
</div> | ||
</figure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.