Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip image processing with eleventy-img - raw image? #133

Closed
alvarotrigo opened this issue Nov 20, 2021 · 3 comments
Closed

Skip image processing with eleventy-img - raw image? #133

alvarotrigo opened this issue Nov 20, 2021 · 3 comments
Labels
enhancement New feature or request needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.

Comments

@alvarotrigo
Copy link

alvarotrigo commented Nov 20, 2021

I have some images on the blog posts that are on the .md file on the layout front matter as images to use for sharing in social media and as a thumbnail.

Those images still need to be moved to the _site folder and I would like to move them only once and only if they change.
That's why I considered using eleventy-img for them instead of just using fs.copyFile.

I want to make use of the eleventy-img cache for this but i don't want eleventy-img to process them at all.
They are in png and for some reason eleventy-img ends up creating a bigger file.

Source file 5.9Kb and output file is 7.7Kb.
Both png.

Is there a way to tell eleventy-img we want to skip any kind of image processing?

I tried using sharOptions to pass the raw option, but it doesn't seem to do the trick:

                await Image(src, {
			formats: ["png"],
			outputDir: outputDir,
			useCache: false,
			sharOptions: {
				raw: true
			},

			// Define custom filenames for generated images
			filenameFormat: function (id, src, width, format, options) {
				const name = path.basename(src, format);

				return `${name}${format}`;
			}
		})
@alvarotrigo alvarotrigo changed the title Skip image processing with eleventy-img? Skip image processing with eleventy-img - raw image? Nov 20, 2021
@zeroby0
Copy link
Contributor

zeroby0 commented Nov 20, 2021

https://www.11ty.dev/docs/plugins/image/#output-widths

widths: [null] (default, keep original width)

That should skip processing the images.

Another option is to write your own shortcode with fs.copyFile, but don't copy if eleventy-img.getHash() returns the same hash.

There's also eleventy passthrough copy, but I don't recall if it copies on every build.


Also, maybe we can check internally if the output file size is larger, and print a warning or not transform the file if the dimensions don't change.

Assuming this isn't a known bug, I encourage you to report it on the sharp repo.

@zachleat
Copy link
Member

Hmm, I think this would request be better invested in incremental build support, which already works with passthroughCopy

https://www.11ty.dev/docs/usage/incremental/#passthrough-copy

Note the pretty hefty limitation right now that incremental builds require a full build on cold start https://www.11ty.dev/docs/usage/incremental/#cold-start 11ty/eleventy#984

Given that information, I will still put this on the enhancement queue for upvotes but (imo) the muscle would be better spent on improving incremental build support.

@zachleat zachleat added enhancement New feature or request needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. labels Feb 23, 2022
@zachleat
Copy link
Member

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

View the enhancement backlog here. Don’t forget to upvote the top comment with 👍!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.
Projects
None yet
Development

No branches or pull requests

3 participants