cleverage / daltons Goto Github PK
View Code? Open in Web Editor NEWa command-line tool that computes optimal image widths to put in srcset attributes of responsive images
Home Page: https://cleverage.github.io/daltons/
License: MIT License
a command-line tool that computes optimal image widths to put in srcset attributes of responsive images
Home Page: https://cleverage.github.io/daltons/
License: MIT License
Node.js 10 is the new LTS:
https://medium.com/@nodejs/october-brings-node-js-10-x-to-lts-and-node-js-11-to-current-ae19f8f12b51
Should be an independent script.
Tutorial: https://medium.com/@fsjohnny/using-google-analytics-api-with-node-js-eb1f5af3375a
Depends on #6
There are only two hard things in Computer Science: cache invalidation and naming things. — Phil Karlton
True.
responsive-image-widths
is not easy to spell (image
or images
? width
or widths
?) and type in a shell, so we would like to rename it to something shorter, and either more explicit or more fun/memorable.
Current options:
👍 srcset-sizer
😁 daltons
(there is already a dalton
package on npm, but there should be no ambiguity)
🎉 BRITS
: Better Responsive Image Tools Selection
❤️ RIWAL
: Responsive Image Widths et AL.
You can vote with reactions, and suggest other names in comments.
Currently the documentation say to run a commande for each sources.
We could make the script return a sizes list to each sources of a picture element with media query detected when runing resize by puppeteer.
Related: #266
It looks like Google Analytics' own "Browser Size" dimension we dismiss here gives a smaller viewport width than our own computed value:
I guess it doesn't include the scrollbar width.
As most Analytics solutions only provide viewport widths and nothing about screen densities, this would help use Daltons without requiring addition of custom dimensions months in advance.
For example, we know that there is a strong correlation between thinner viewports and high density:
https://twitter.com/TimVereecke/status/1121757778400481282
Because there is not existing statistics for a new website.
.editorconfig
package.json
keyHello,
There is no return without verbose
or destFile
option.
I think we should display a spinner during process and only print final return at end.
Basic users would only have result or error.
Should help reduce computing time
Should both:
I guess it's time to upgrade the Node.js versions to latest active LTS at least.
1 - remove --verbose
from example/simple/run.sh
2 - cd example/simple
3 - `./run.sh
It display help information for cli
Run the script silently
Currently not compatible, staying on v4.x
When in verbose mode.
Might use https://github.com/kroitor/asciichart
Use Google's Pupeteer
Will be useful for multiple images or single image with Art Direction
Screen with >2dppx
density require lower quality, more compressed, images:
https://observablehq.com/@eeeps/visual-acuity-and-device-pixel-ratio
It might be better having different images widths for high density screens (most being mobiles) and low density screens.
Serving lower quality images to high density screens requires using <picture>
with a density media query:
<picture>
<source
media="(min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 2)"
sizes="…"
srcset="
image-q10-720.jpg 720w,
image-q10-1280.jpg 1280w,
image-q10-1400.jpg 1400w">
<img
src="image-q80-320.jpg"
sizes="…"
srcset="
image-q80-360.jpg 360w,
image-q80-800.jpg 800w,
image-q80-1024.jpg 1024w">
</picture>
The 2dppx
threshold should be a parameter.
@welcoMattic after working on it a little more, I'm not sure I understand the intent of this part:
https://github.com/cleverage/daltons/blob/master/src/index.js#L116-L125
result.centroids.forEach((centroid) => {
const centroidWidth = centroid[0]
closestRealWidths.push(
[...perfectWidths.keys()].reduce((prev, curr) => {
return Math.abs(prev - centroidWidth) > Math.abs(curr - centroidWidth)
? curr
: prev
}),
)
})
Could you explain why you don't use the centroids directly?
It is currently missing
bin
to expose responsive-image-sizes.js
as a binany to be run in cli without node
command.
main
to set responsive-image-sizes.js
default importable js of the package to making it usable as a dependency.
Files:
One option to overwrite all files, or one option per file?
For example, allow settings rounded screen densities to [1, 1.5, 2, 2.5]
Aims:
For example, a CSV exported from a Google Analytics report starts like this:
# ----------------------------------------
# nicolas-hoizey.com
# Viewport et densité d'écran
# 20180501-20180731
# ----------------------------------------
Viewport width,Screen density,Pageviews
1920,1,"3,505"
1440,2,"1,341"
1366,1,"1,194"
375,2,725
360,3,587
;
separator"
)Should help reduce computing time
Could be useful if we only want the list of image width variations, for example
It should not be necessary to explain what “contexts” means, what it contains.
I'm trying to write results in a file with -f option, but I catch this error
Step 2: get variations of image width across viewport widths
Launch headless Chrome
Go to https://www.courbet.test
Checking widths of image main picture.c-block__img > img
Finished at viewport: 1280px
Couldn’t load page located at https://www.courbet.test:
ReferenceError: writeFile is not defined
Did you face this case before?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.