Comments (6)
Hej @vinamelody, just added support for this. In your .md file just use imgproc
shortcode, like this:
{{< imgproc [name_of_image] [options] />}}
-> {{< imgproc hello "Fit 500x200" />}}
or with caption:
{{< imgproc hello "Fit 500x200" >}}
Hello friend
{{< />}}
For more info, please look at image processing docs (the same docs you mentioned above)
from hugo-theme-hello-friend.
Thank you :)
from hugo-theme-hello-friend.
Hi, when I tried using it for example
{{< imgproc xinhua-fried-beehoon-dish.jpg "Fit 500" >}}
, the error: unrecognized character in shortcode action: U+002E '.'. Note: Parameters with non-alphanumeric args must be quoted{{< imgproc "xinhua-fried-beehoon-dish.jpg" "Fit 500" >}}
, the error: Invalid image processing command: Must be one of Fit, Fill or Resize.
By the way, I read an article https://laurakalbag.com/processing-responsive-images-with-hugo/ and tried adding a custom shortcode from the article and it works!
{{/* get file that matches the filename as specified as src="" in shortcode */}}
{{ $src := .Page.Resources.GetMatch (printf "*%s*" (.Get "src")) }}
{{/* set image sizes, these are hardcoded for now, x dictates that images are resized to this width */}}
{{ $tinyw := default "500x q80" }}
{{ $smallw := default "800x q80" }}
{{ $mediumw := default "1200x q80" }}
{{ $largew := default "1500x q80" }}
{{/* resize the src image to the given sizes */}}
{{ .Scratch.Set "tiny" ($src.Resize $tinyw) }}
{{ .Scratch.Set "small" ($src.Resize $smallw) }}
{{ .Scratch.Set "medium" ($src.Resize $mediumw) }}
{{ .Scratch.Set "large" ($src.Resize $largew) }}
{{/* add the processed images to the scratch */}}
{{ $tiny := .Scratch.Get "tiny" }}
{{ $small := .Scratch.Get "small" }}
{{ $medium := .Scratch.Get "medium" }}
{{ $large := .Scratch.Get "large" }}
{{/* only use images smaller than or equal to the src (original) image size, as Hugo will upscale small images */}}
{{/* set the sizes attribute to (min-width: 35em) 1200px, 100vw unless overridden in shortcode */}}
<img
{{ with .Get "sizes" }}sizes='{{.}}'{{ else }}sizes="(min-width: 35em) 1200px, 100vw"{{ end }}
srcset='
{{ if ge $src.Width "500" }}
{{ with $tiny.RelPermalink }}{{.}} 500w{{ end }}
{{ end }}
{{ if ge $src.Width "800" }}
{{ with $small.RelPermalink }}, {{.}} 800w{{ end }}
{{ end }}
{{ if ge $src.Width "1200" }}
{{ with $medium.RelPermalink }}, {{.}} 1200w{{ end }}
{{ end }}
{{ if ge $src.Width "1500" }}
{{ with $large.RelPermalink }}, {{.}} 1500w {{ end }}
{{ end }}'
{{ if .Get $medium }}
src="{{ $medium.RelPermalink | safeURL }}"
{{ else }}
src="{{ $src.RelPermalink | safeURL }}"
{{ end }}
{{ with .Get "alt" }}alt="{{ . | plainify }}"{{ end }}
{{ with .Get "style" }} style="{{ . | safeCSS }}"{{ end }}>
from hugo-theme-hello-friend.
The downside of that, Hugo seems to produce multiple image files upon compilation
from hugo-theme-hello-friend.
@vinamelody please try to use filename without an extension. Error says that the issue is with .
🤔
from hugo-theme-hello-friend.
hmm tried that, and tried wrapping it with double-quote too, it doesn't work.
from hugo-theme-hello-friend.
Related Issues (20)
- Change code snippet's theme when switch main theme
- Image Processing crashes on building a website
- [Question] Combining JS files in footer.html HOT 1
- Media queries are not working in iOS
- `Error building site: TOCSS: failed to transform "css/style.scss" (text/x-scss)` HOT 6
- Embedding TryHackMe badge HOT 1
- Can't Image in markdown syntax
- _index.md non centered text. HOT 1
- Add archive for tweets contenttype
- Question: Add Cover image to archive
- Add PowerShell Syntax Highlighting
- Animated back to top button with CSS HOT 1
- Add share buttons:
- Accessibility: Background and foreground colors do not have a sufficient contrast ratio.
- Accessibility: Links do not have a discernible name
- PWA: Progressive Web App Support
- Sticky navbar HOT 1
- Github Page support
- can't build my site due to a new error HOT 5
- [Help Wanted] How can I adjust the archive page so that it does not contain microblog entries? HOT 2
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 hugo-theme-hello-friend.