
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
img-handler
Advanced tools
Node.js Express url image handler using sharp module to resize JPEG, PNG, WebP, AVIF and TIFF images
The use for this Express Node.js module is to handle images by URL.
This needs to have sharp module installed previously.
npm install img-handler
const imgHandler = require('img-handler');
app.use( '/path', imgHandler() );
// https://domain.com/path/(params)/image.jpg
It's recommended always set 'dir' option
'ext' option will set the extension of the image file
app.use( '/path', imgHandler({
dir: './images/', // default './images'
ext: '.png' // default '.jpg'
}));
// recommended use of absolute path
app.use( '/path', imgHandler({
dir: path.resolve('./images/')
}));
If the image extension is not in the url it will use the one set in the 'ext' option or default
This option will assign where the parameters to use will be getting from
app.use( '/path', imgHandler({
dir,
params: 'route' // default: 'route', opts: ['route', 'query', 'none']
}));
route : domain.com/path/{params}/image.jpg
query : domain.com/path/image.jpg?{params}
none : domain.com/path/image.jpg
Options are simple letters, for 'route' param are uppercase letters, and 'query' param is not case sensitive
'route' param can omit key "S" and just put the value.
Setting 'size' and, 'width' or 'height', the setted value will be that of 'size'.
Setting the same option more times, the setted value will be the first.
domain.com/path/100x100Fw/image.jpg
Formats are simple letters too. If not set the 'quality' option, it will take the default value for each one.
Setting default values for each parameter, these will be assigned if no value has been setted for said option in 'route' or 'query', even for 'none'.
app.use( '/path', imgHandler({
dir,
ext,
params,
defaults: {
size: {
width: 100,
height: 100
},
format: {
type: 'jpeg',
options: {
quality: 80
}
}
}
}));
Copyright 2021 apvald.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Node.js Express url image handler using sharp module to resize JPEG, PNG, WebP, AVIF and TIFF images
We found that img-handler 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.