Comments (6)
sharp-cli
is perfect! Here's my usage:
{
"scripts": {
"start": "npm run thumbnail && jus serve ./src",
"build": "npm run thumbnail && jus compile ./src ./dist",
"thumbnail": "sharp -i ./src/images/*.jpg -o ./src/thumbnails resize 230"
}
}
@zeke, thanks for pointing sharp-cli
out to me. I guess next time I'll do some research before diving into rolling my own solution :p
Closing the issue.
from jus.
Hmm, looks like node-thumbnail
depends on imagemagick
- we probably don't want to add a non-npm dependency.
from jus.
I originally wrote pure stream of consciousness, but now am going to label these as two separate ideas. I think the first one is "meh" and like my second idea better.
Idea 1: Hmm... these are good questions. I like, in theory, the principle of auto-thumbnailing large images. I feel like the API could probably be even simpler, like just tacking "_thumb.png" or "_100x200.jpg" to the end of the filename. But that could mess up existing projects if they already had files named that way, which would be sad. It is also heavy on the magic, unexpected behavior... although admittedly if you had an image that ended with "_100x200.jpg" and you weren't expecting it to be 100x200 pixels, that would be kind of unexpected too.
Idea 2: Didn't HTML5 add some new mechanism like an image srcset that lets you specify multiple resolutions for images? Maybe we could do something with that. (Goes to Google to find that thing...) Yeah... link dump:
- http://caniuse.com/#search=srcset
- https://css-tricks.com/responsive-images-youre-just-changing-resolutions-use-srcset/
OK, thinking out loud here... Could we simply use an algorithm like:
- Find all
<img>
tags that point to a "large" image (where "large" is some heuristic to determine whether it deserves to be thumbnailed, like "larger than 64x64 pixels" or "larger than 5kb") - If that
<img>
tag does not already have asrcset
attribute - Generate thumbnails at a few different sizes and add the corresponding
srcset
attribute to theimg
tag.
That seems to be the cool kid, let the browser decide what resolution to download, new-age way to do it. (I've never used srcset before, because I hate my users and just waste their bandwidth I'm lazy and never thought about it before.)
from jus.
node-thumbnail depends on imagemagick
sharp is working well for resizing electron app icons. It has a native dependency that has to be compiled at install time, but it works and it's fast. I tried jimp
and it had lots of issues.
only generate thumbnails that were requested
👍
srcset
attribute
👍 cool idea if it works.
Part of me is cool with adding this feature, but another part of me wants to remove all the image metadata magic from jus entirely: the EXIF extraction, image dimension checking, color palette extraction, etc. Those things are the heaviest of jus's dependencies, and I suspect they are probably also the least-used. 🤔
I personally would prefer to have a CLI (entirely apart from jus) that could generate thumbnails...
from jus.
sharp
looks perfect! I like the external CLI idea. It could be something as simple as passing it files and having it generate thumbnails to some destination directory/file. Something like:
$ gen-thumbnail ./images/*.jpeg -o ./images/thumbnails
We can leave the actual usage of the generated images to the user - they could reference the images directly, or use srcset
, or whatever they want.
A nice benefit to this approach is that the CLI can take additional options, like an output file name suffix for example.
I will probably not get to working on this until next week or the week after, but I will ping you guys when I do.
Leaving this issue open for further discussion, but if anyone else feels like this is a good solution feel free to close the issue.
from jus.
This seems like a common enough problem that there are probably already some good modules for.
This looks interesting: https://github.com/vseventer/sharp-cli
If nothing else, it might be a good reference for whatever you end up building.
from jus.
Related Issues (20)
- Consider using `consolidate.js` library for abstracting different template options
- Feature: Add YAML support for 'page' type files (not just for 'datafile' type) HOT 1
- List of excluded files HOT 8
- Inkscape-generated SVG error from `image-size` library HOT 1
- Don't try to parse `svg` fonts as images HOT 4
- Moved jus repos to a GitHub organization! HOT 1
- Replaceable Markdown processor HOT 2
- path-exists should be a dependency, not a dev-dependency?
- Modularizing jus HOT 19
- Serve a unique favicon.ico per project HOT 12
- Remove old 404 ¯\_(ツ)_/¯ message
- Remove unneeded 'href-type' dependency
- Overwriting /api HOT 9
- Can we import CSS files from node_modules? HOT 1
- Allow Sass Imports HOT 1
- jus development stalled by Node 4 support HOT 3
- Support for more handlebars helpers HOT 2
- Dynamic pages, filtering data, custom helpers, and other templating languages? HOT 8
- README is not up to date
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jus.