
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
uploadcare-picture
Advanced tools
This is an Uploadcare responsive <picture>
component. It provides
more control over image behavior: you can adjust image sizes to different
media queries, control output formats, etc.
You also get:
You can get the component via npm:
npm install uploadcare-picture
You would not need an Uploadcare account for testing purposes: just use UUIDs provided in this readme. However, implementing the component requires you to have an Uploadcare account; you can get one here.
The function can be used directly or through one of the adapters.
import getPictureObject from 'uploadcare-picture'
const uuid = '18d1c520-c52d-4c34-82a0-7e07dcbcf105'
const options = {
sizes: {
'(max-width: 1024px)': '768px',
'default': '1024px'
},
formats: ['jpg', 'webp'],
name: 'example'
}
const picture = getPictureObject(uuid, options)
The function provides an object in the output, like this:
{
sources: [
{
srcset: `https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/768x/-/format/webp/example.webp 1x, https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/1536x/-/format/webp/example.webp 2x`,
type: 'image/webp',
media: '(max-width: 1024px)',
sizes: '768px',
},
{
srcset: `https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/1024x/-/format/webp/example.webp 1x, https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/2048x/-/format/webp/example.webp 2x`,
type: 'image/webp',
sizes: '1024px',
},
{
srcset: `https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/768x/-/format/jpg/example.jpg 1x, https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/1536x/-/format/jpg/example.jpg 2x`,
type: 'image/jpg',
media: '(max-width: 1024px)',
sizes: '768px',
},
{
srcset: `https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/1024x/-/format/jpg/example.jpg 1x, https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/2048x/-/format/jpg/example.jpg 2x`,
type: 'image/jpg',
sizes: '1024px',
},
],
image: {
alt: 'example',
src: `https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/1024x/-/format/auto/example`,
srcset: `https://ucarecdn.com/18d1c520-c52d-4c34-82a0-7e07dcbcf105/-/resize/2048x/-/format/auto/example 2x`,
sizes: '1024px',
},
}
You can further transpile such objects to <picture>
via any library
or framework you like.
string|number
Required, if not set sizes.default
.
Sets the width of an <img />
element.
object
Required, if not set width
.
Keys in the object are media queries while sizes define your picture dimensions for them.
array<string>
Optional, default values is ['auto']
.
An array holding the allowed formats for your picture sources.
array<number|string>|number|string
Optional, default value is [1, 2]
.
An array of pixel density value(-s) for resizing your picture sources.
string
Optional.
An RFC3986-compliant filename.
import UploadcarePicture from 'uploadcare-picture/adapters/jsx'
const Picture = () =>
<UploadcarePicture
uuid='18d1c520-c52d-4c34-82a0-7e07dcbcf105'
formats={['webp', 'jpg']}
sizes={{
'(max-width: 1024px)': '768px',
'default': 1024,
}}
name='example' />
import {configure} from 'nunjucks'
import UploadcarePicture from 'uploadcare-picture/adapters/nunjucks'
const nunjucks = configure('templates', {autoescape: false})
nunjucks.addExtension('UploadcarePicture', new UploadcarePicture())
const template = `{% uploadcarePicture
uuid='18d1c520-c52d-4c34-82a0-7e07dcbcf105',
formats=['webp', 'jpg'],
sizes={
'(max-width: 1024px)': 768,
'default': 1024
},
name='example'
%}`
const picture = nunjucks.renderString(template)
Run linters and tests
npm test
GitHub issues and PRs are welcome. You can also post any questions around the UC Community Area.
1.1.0 - 2018.03.20
uploadcare-picture/adapters/nunjucks
and
uploadcare-picture/adapters/jsx
works.FAQs
Create responsive picture with Uploadcare CDN.
The npm package uploadcare-picture receives a total of 1 weekly downloads. As such, uploadcare-picture popularity was classified as not popular.
We found that uploadcare-picture 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.