Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Theme
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Theme
Commits
a9816531
Commit
a9816531
authored
1 year ago
by
alexisben
Browse files
Options
Downloads
Patches
Plain Diff
add tool to debug image
parent
3db01e4b
No related branches found
Branches containing commit
Tags
v3.1.2
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config.yaml
+6
-2
6 additions, 2 deletions
config.yaml
layouts/partials/blocks/templates/pages/list.html
+11
-1
11 additions, 1 deletion
layouts/partials/blocks/templates/pages/list.html
layouts/partials/footer/debug.html
+89
-18
89 additions, 18 deletions
layouts/partials/footer/debug.html
with
106 additions
and
21 deletions
config.yaml
+
6
−
2
View file @
a9816531
...
...
@@ -108,7 +108,7 @@ params:
chapter
:
mobile
:
350
tablet
:
450
desktop
:
12
80
desktop
:
80
0
features
:
mobile
:
350
tablet
:
400
...
...
@@ -126,6 +126,10 @@ params:
tablet
:
100
desktop
:
255
pages
:
list
:
mobile
:
400
tablet
:
800
desktop
:
300
large
:
mobile
:
400
tablet
:
800
...
...
@@ -209,7 +213,7 @@ params:
item
:
mobile
:
350
tablet
:
990
desktop
:
9
00
desktop
:
6
00
papers
:
hero
:
mobile
:
400
...
...
This diff is collapsed.
Click to expand it.
layouts/partials/blocks/templates/pages/list.html
+
11
−
1
View file @
a9816531
...
...
@@ -28,7 +28,17 @@
</div>
{{ if $show_images }}
{{- partial "pages/page-media.html" . -}}
<div
class=
"media"
>
{{- if .Params.image -}}
{{- partial "commons/image.html"
(dict
"image" .Params.image
"sizes" site.Params.image_sizes.blocks.pages.list
) -}}
{{- else -}}
{{- partial "commons/image-default.html" -}}
{{- end -}}
</div>
{{ end }}
</article>
{{ else }}
...
...
This diff is collapsed.
Click to expand it.
layouts/partials/footer/debug.html
+
89
−
18
View file @
a9816531
...
...
@@ -145,6 +145,36 @@
}
}
.img-debug
{
font-size
:
1.1rem
;
line-height
:
1.2
;
padding
:
10px
;
background-color
:
white
;
color
:
black
;
display
:
block
;
position
:
absolute
;
bottom
:
0
;
left
:
0
;
font-family
:
sans-serif
;
white-space
:
nowrap
;
opacity
:
0.9
;
}
.img-debug
small
{
font-size
:
0.9rem
;
font-family
:
sans-serif
;
display
:
none
;
}
.img-debug
:hover
small
{
display
:
block
;
}
.img-debug.is-bad
{
background
:
tomato
;
color
:
black
;
}
</style>
<script>
...
...
@@ -157,6 +187,9 @@
if
(
e
.
ctrlKey
&&
e
.
key
===
'
w
'
)
{
document
.
body
.
classList
.
toggle
(
'
full-width
'
);
}
if
(
e
.
ctrlKey
&&
e
.
key
===
'
i
'
)
{
showImageDimension
();
}
});
window
.
addEventListener
(
'
pointermove
'
,
e
=>
{
...
...
@@ -174,23 +207,61 @@
})
})
function
responsiveImageDebugOutput
(
img
)
{
if
(
!
img
)
{
throw
new
TypeError
(
"
Expected an image node. Got none.
"
);
}
const
listener
=
function
()
{
const
pixelRatio
=
window
.
devicePixelRatio
>
1
?
2
:
1
;
const
dimensionWidth
=
img
.
naturalWidth
*
pixelRatio
;
const
dimensionHeight
=
img
.
naturalHeight
*
pixelRatio
;
console
.
log
(
`
-------------------------
Rendered size:
${
img
.
width
}
x
${
img
.
height
}
Intrinsic size:
${
dimensionWidth
}
x
${
dimensionHeight
}
Device Pixel Ratio:
${
window
.
devicePixelRatio
}
-------------------------
`
);
};
if
(
img
.
complete
)
listener
();
//img.addEventListener('load', listener);
function
showImageDimension
()
{
document
.
querySelectorAll
(
'
img
'
).
forEach
(
img
=>
{
const
listener
=
function
()
{
// Return if svg
if
(
img
.
src
.
split
(
'
.
'
)[
1
]
===
'
svg
'
)
return
;
const
threshold
=
0.2
,
// 20% of tolerance
parent
=
img
.
parentElement
,
pixelRatio
=
window
.
devicePixelRatio
,
dimensions
=
{
width
:
img
.
naturalWidth
*
pixelRatio
,
height
:
img
.
naturalHeight
*
pixelRatio
},
target
=
{
width
:
img
.
width
*
window
.
devicePixelRatio
,
height
:
img
.
height
*
window
.
devicePixelRatio
},
essential
=
`<b>Loaded</b> :
${
dimensions
.
width
}
x
${
dimensions
.
height
}
\n
<b>Needed</b> :
${
target
.
width
}
x
${
target
.
height
}
`
,
result
=
`
Rendered size:
${
img
.
width
}
x
${
img
.
height
}
Intrinsic size:
${
dimensions
.
width
}
x
${
dimensions
.
height
}
Device Pixel ratio:
${
window
.
devicePixelRatio
}
`
,
p
=
parent
.
querySelector
(
'
.img-debug
'
)
||
document
.
createElement
(
'
p
'
),
small
=
document
.
createElement
(
'
small
'
);
small
.
innerText
=
result
;
p
.
innerHTML
=
essential
p
.
append
(
small
);
p
.
classList
.
add
(
'
img-debug
'
);
const
ratio
=
getImageRatio
(
dimensions
,
target
)
if
(
ratio
>
threshold
)
{
p
.
classList
.
add
(
'
is-bad
'
);
}
else
{
p
.
classList
.
remove
(
'
is-bad
'
);
}
const
debug
=
img
.
querySelector
(
'
.img-debug
'
);
if
(
debug
)
parent
.
removeChild
();
parent
.
append
(
p
);
parent
.
style
.
position
=
'
relative
'
;
};
if
(
img
.
complete
)
listener
();
img
.
addEventListener
(
'
load
'
,
listener
);
window
.
addEventListener
(
'
resize
'
,
listener
);
});
}
function
getImageRatio
(
source
,
target
)
{
const
widthRatio
=
Math
.
abs
((
source
.
width
-
target
.
width
)
/
Math
.
max
(
source
.
width
,
target
.
width
)),
heightRatio
=
Math
.
abs
((
source
.
height
-
target
.
height
)
/
Math
.
max
(
source
.
height
,
target
.
height
));
return
(
widthRatio
+
heightRatio
)
/
2
;
}
</script>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment