Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
The ipx npm package is an image processing server that allows you to manipulate images on-the-fly. It supports various image transformations such as resizing, cropping, and format conversion, making it useful for web applications that need dynamic image processing.
Resizing Images
This feature allows you to resize images to specified dimensions. In the code sample, the image is resized to a width of 300 pixels and a height of 200 pixels.
const ipx = require('ipx')();
const url = '/_ipx/w_300,h_200/image.jpg';
const result = await ipx(url);
Cropping Images
This feature allows you to crop images to specified dimensions. In the code sample, the image is cropped to a width of 300 pixels and a height of 200 pixels.
const ipx = require('ipx')();
const url = '/_ipx/c_crop,w_300,h_200/image.jpg';
const result = await ipx(url);
Format Conversion
This feature allows you to convert images to different formats. In the code sample, the image is converted to the WebP format.
const ipx = require('ipx')();
const url = '/_ipx/f_webp/image.jpg';
const result = await ipx(url);
Sharp is a high-performance image processing library that supports resizing, cropping, and format conversion. It is known for its speed and efficiency, making it a popular choice for server-side image processing. Compared to ipx, sharp is more of a low-level library that requires more manual setup and configuration.
Jimp is a JavaScript image processing library that supports various image manipulations such as resizing, cropping, and format conversion. It is easy to use and does not require any external dependencies. Compared to ipx, Jimp is more suitable for client-side applications and smaller projects.
GraphicsMagick (gm) is a Node.js wrapper for the GraphicsMagick and ImageMagick image processing libraries. It supports a wide range of image manipulations and is highly configurable. Compared to ipx, gm offers more advanced features but requires the installation of external software.
High performance, secure and easy to use image proxy based on sharp and libvips.
You can use ipx
command to start server using:
$ npx ipx
Latest docker image is automatically built under pooya/ipx.
Run a test server:
docker run \
-it \
--rm \
--volume ./storage:/app/storage:ro \
--volume ./cache:/app/cache \
--port 3000:3000
pooya/ipx
Using docker-compose:
version: '3'
services:
ipx:
image: pooya/ipx
volumes:
- ./storage:/app/storage:ro
- ./cache:/app/cache
ports:
- 3000:3000
You can use IPX as a Connect/Express middleware or directly use IPX class.
import { IPX, IPXMiddleware } from 'ipx'
const ipx = new IPX(/* options */)
const app = express()
app.use('/image', IPXMiddleware(ipx))
/{format}/{operations}/{src}
Operations are separated by a colon ,
(Example: op1,op2
) and their arguments separated using underscore _
(Example: s_200_300
)
ََUse _
value in place for {format}
or {operations}
to keep original values of source image.
Possible values for format: jpeg
,webp
or png
.
Just change format to webp
and keep other things same as source:
http://cdn.example.com/webp/_/avatars/buffalo.png
Keep original format (png
) and set width to 200
:
http://cdn.example.com/_/w_200/avatars/buffalo.png
Resize to 200x300px
using embed
method and change format to jpg
:
http://cdn.example.com/jpg/s_200_300,embed/avatars/buffalo.png
Operation | Arguments | Example | Description |
---|---|---|---|
s | width , height | s_200_300 | Resize image. |
w | width | w_200 | Change image with. |
h | height | h_200 | Change image height. |
embed | - | embed | Preserving aspect ratio, resize the image to the maximum width or height specified then embed on a background of the exact width and height specified. |
max | - | max | Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to the width and height specified. |
min | - | min | Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to the width and height specified. |
Config can be customized using IPX_*
environment variables.
IPX_PORT
(or PORT
)
Default: 3000
IPX_INPUT_ADAPTER
fs
IPX_INPUT_DIR
storage
IPX_CACHE_ADAPTER
fs
IPX_CACHE_DIR
cache
IPX_CACHE_CLEAN_CRON
0 0 3 * * *
(every night at 3:00 AM)IPX_CACHE_CLEAN_MINUTES
24 * 60
(24 hours)Import client:
import { img } from 'ipx/client'
const { img } = require('ipx/client')
img()
is a factory function to configure base options:
// getImage: (path, opts?, format?) => URL
const getImage = img({
baseURL = 'https://cdn.example.com',
basePath = 'uploads',
opts = [], // Default opts
format = 'jpg',
presets: {
chrome400: {
format: 'webp',
opts: { s: ['400', '400']}
}
}
})
getImage('posts/ipx.png', { w: 200 }) // => https://cdn.example.com/jpg/w_200/uploads/posts/ipx.png
getImage.chrome400('posts/ipx.png') // => https://cdn.example.com/webp/s_400_400/uploads/posts/ipx.png
MIT - Pooya Parsa
FAQs
High performance, secure and easy-to-use image optimizer.
The npm package ipx receives a total of 192,924 weekly downloads. As such, ipx popularity was classified as popular.
We found that ipx demonstrated a healthy version release cadence and project activity because the last version was released less than 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.