Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
postcss-image-dimensions
Advanced tools
PostCSS plugin for image height, image ratio and image color in CSS
PostCSS plugin for using image width, height, ratio and color data in your CSS.
Note: All width, height and ratio helpers include a 2x resolution version. For example, image-width()
becomes image-width-2x()
. The assumption is that the 2x image is the original image found and the 1x image is half of that.
Install package as a dependency.
yarn add postcss-image-dimensions
Add to your PostCSS build chain.
const postcssImageDimensions = require('postcss-image-dimensions');
postcss([
postcssImageDimensions({
globPattern: ['./src/images/**/*', './other/images/**/*'], // String or Array of strings
cachePath: './.cache'
})
]);
Use available helper methods in your CSS.
/* Input */
.example-image {
width: image-width('src/images/example.jpg');
}
/* Output */
.example-image {
width: 200px;
}
Important: All image paths used with the CSS helpers must be absolute from the root of your project.
image-width()
- Width in pixels.image-width-2x()
- Width in pixels.image-width-ratio()
- Ratio of width as a percentage (to 4 decimal places).image-width-ratio-2x()
- Ratio of width as a percentage (to 4 decimal places).image-height()
- Height in pixels.image-height-2x()
- Height in pixels.image-height-ratio()
- Ratio of height as a percentage (to 4 decimal places).image-height-ratio-2x()
- Ratio of height as a percentage (to 4 decimal places).image-color()
- The average color of the image as a hexadecimal string or transparent
if image is transparent.All examples below assume the following image has been used.
Example Input | Example Output |
---|---|
image-width('test/juice.jpg') | 125px |
image-width-2x('test/juice.jpg') | 250px |
image-width-ratio('test/juice.jpg') | 117.9245% |
image-width-ratio-2x('test/juice.jpg') | 118.4834% |
image-height('test/juice.jpg') | 106px |
image-height-2x('test/juice.jpg') | 211px |
image-height-ratio('test/juice.jpg') | 84.8% |
image-height-ratio-2x('test/juice.jpg') | 84.4% |
image-color('test/juice.jpg') | #cbbc8e |
'./src/images/**/*'
Override where the plugin should look for images. Paths need to be provided as glob patterns. See globby for supported patterns.
'./.cache'
The plugin creates a cache of all image data so it doesn't have to keep processing images each time.
FAQs
PostCSS plugin for image height, image ratio and image color in CSS
The npm package postcss-image-dimensions receives a total of 0 weekly downloads. As such, postcss-image-dimensions popularity was classified as not popular.
We found that postcss-image-dimensions 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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.