
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
Generate responsive images and additional Pug templates, using sharp image processing and JSON configs.
It's not just sharp, it's pugsharp!
Batch resize and reformat images for your Pug project.
The pugsharp Node.js module is evolving, based on the specifications of the fictional Pug Image Transormer (PIT). For more details, visit PIT's GitHub Repository.
If you have not already done so, download and install Node.js and npm.
pugsharp.json configuration file.npx pugsharp in the console.Watch the magic happen.
Put a pugsharp.json configuration file in your image directory, right next to the images.
Each source image will have its own directory, based on the image name. That's where the generated images will be.
Below is the minimal required configuration for an image in the pugsharp.json file.
[
{
"img": "pug.png",
"format": "jpg",
"from": 100,
"to": 1200,
"step": 300
}
]
[
{
"img": "pug.png",
"format": "jpeg",
"from": 100,
"to": 1200,
"step": 300,
"special": 10,
"sharp-jpeg": {
"mozjpeg": true,
"quality": 80
}
},
{
"img": "pug2.avif",
"format": ["avif","webp"],
"from": 300,
"to": 2000,
"step": 100,
"special": [1, 40],
"lazy": false,
"data-src": true,
"sharp-avif": {
"quality": 70,
"effort": 7
},
"sharp-webp": {
"quality": 80,
"effort": 5
}
}
]
"img": File name of the image.
"format": Target image format(s).
"from": Smallest target image size.
"to": Largest target image size.
"step": Pixel step size between small and large.
"special": Additional special image size(s).
"lazy": If false, loading="lazy" won't be applied to the img element. Default is true.
"data-src": If true, you'll get <img data-src="...">, instead of <img src="...">. Same for <source srcset>.
"sharp-*": For detailed format options, see the sharp format documentation.
As a bonus, pugsharp generates a Pug mixin template for each processed image, further simplifying the integration of responsive images into your Pug projects.
Within the directory of any processed image, you'll find a complementary pugsharp.pug file that contains a ready-to-use mixin. This mixin enables easy integration of the generated images.
Simply include the pugsharp.pug file and call the mixin, providing the image path, alt text and optionally, additional attributes.
Include the mixin and call it with the image's file path, alternative text and the sizes property for the source tags:
+img('img source path', 'alt text, {sizes})
Example:
include pug/pugsharp.pug
+img('pug/pug-100.jpg', 'pug image', {sizes:'3vw'})
Here's how the Pug mixin translates into sample HTML output:
<picture>
<source srcset="pug/pug-100.avif 100w, pug/pug-200.avif 200w" type="image/avif" sizes="3vw">
<source srcset="pug/pug-100.jpg 100w, pug/pug-200.jpg 200w" type="image/jpg" sizes="3vw">
<img src="pug/pug-100.jpg" alt="pug image" loading="lazy">
</picture>
Include the mixin and call it with additional attributes:
+img('img source path', 'alt text', {attributes})
It is possible to define any valid HTML attribute for the <img> tag in the mixin, in a JavaScript object:
include img2/pugsharp.pug
+img('img2/img2-200.jpg', 'pug image', {sizes:'4vw', class:'paw', decoding:'sync'})
Only the sizes property will be added to source tags. All other attributes will be applied to the img element.
Sample HTML output with additional attributes on the img element and sizes on the source elements:
<picture>
<source srcset="img2/img2-100.avif 100w, img2/img2-200.avif 200w" type="image/avif" sizes="4vw">
<source srcset="img2/img2-100.jpg 100w, img2/img2-200.jpg 200w" type="image/jpg" sizes="4vw">
<img src="img2/img2-200.jpg" alt="pug image" loading="lazy" class="paw" decoding="sync">
</picture>
See the Mozilla Developer Network (MDN) documentation for more details on image attributes.
pugsharp.pug files for specified images will be overwritten when you run pugsharp.pugsharp.json configuration file.Your support, whether through code, feedback, or donations on Ko-Fi, are invaluable to keeping this project thriving!
On GitHub, your contributions can help in various ways:
On Ko-Fi, your donations support:
Every bit of support motivates and helps maintain the project's quality and accessibility.
Support on Ko-Fi | Contribute on GitHub
Thank you for your generosity and belief in this project! Let's pug it!
FAQs
Generate responsive images and additional Pug templates, using sharp image processing and JSON configs.
The npm package pugsharp receives a total of 13 weekly downloads. As such, pugsharp popularity was classified as not popular.
We found that pugsharp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.