
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
@opensourceframework/next-images
Advanced tools
Import images (jpg, jpeg, png, svg, gif, ico, webp, jp2, avif) in Next.js applications. Fork of next-images with TypeScript support.
Import images (jpg, jpeg, png, svg, gif, ico, webp, jp2, avif) in Next.js applications
This is a maintained fork of the original next-images package by Aref Aslani (twopluszero), with TypeScript support and continued maintenance.
Notice: This package is deprecated. Next.js 10+ includes a built-in Image component that provides automatic image optimization, lazy loading, and better performance. We strongly recommend migrating to
next/imagefor new projects.
npm install @opensourceframework/next-images
or
yarn add @opensourceframework/next-images
or
pnpm add @opensourceframework/next-images
Create or update your next.config.js:
// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages();
Then import images in your components:
// Using import
import img from './my-image.jpg';
export default function MyComponent() {
return <img src={img} alt="My Image" />;
}
// Using require
export default function MyComponent() {
return <img src={require('./my-image.jpg')} alt="My Image" />;
}
inlineImageLimitMaximum file size (in bytes) for inlining images as Base64. Images smaller than this limit will be inlined as data URLs.
number | false8192 (8KB)false: Disable inlining entirely// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
inlineImageLimit: 16384, // 16KB
});
assetPrefixServe images from a CDN or external domain.
// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
assetPrefix: 'https://cdn.example.com',
});
basePathSet the base path for your application.
// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
basePath: '/my-app',
});
dynamicAssetPrefixEnable dynamic asset prefix resolution at runtime. Useful when assetPrefix can change dynamically.
// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
assetPrefix: 'https://cdn.example.com',
dynamicAssetPrefix: true,
});
fileExtensionsCustomize which file extensions to handle.
string[]["jpg", "jpeg", "png", "svg", "gif", "ico", "webp", "jp2", "avif"]// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
fileExtensions: ['jpg', 'jpeg', 'png', 'webp'],
});
excludeExclude specific paths from the loader. Useful when you want to handle certain files with a different loader (e.g., svg-react-loader).
// next.config.js
const path = require('path');
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
exclude: path.resolve(__dirname, 'src/assets/svg'),
});
nameCustomize the output file name template.
string"[name]-[hash].[ext]"// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
name: '[name].[hash:base64:8].[ext]',
});
Available tokens: [name], [hash], [hash:base64:N], [ext]. See webpack/loader-utils for more options.
esModuleEnable ES modules syntax for the output.
booleanfalse// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
esModule: true,
});
When enabled, you need to use .default when using require():
// With esModule: true
<img src={require('./image.png').default} />
// import statements work as before
import img from './image.png';
This package includes TypeScript type definitions. For image imports, add a reference to the types in your project:
Create additional.d.ts:
/// <reference types="@opensourceframework/next-images" />
Update tsconfig.json:
{
"compilerOptions": {
// ...
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "additional.d.ts"]
}
next/imageNext.js 10+ includes a built-in Image component that provides automatic optimization. If you want to use next/image, set inlineImageLimit: false to disable Base64 inlining:
// next.config.js
const withImages = require('@opensourceframework/next-images');
module.exports = withImages({
inlineImageLimit: false,
});
Then use the Image component:
import Image from 'next/image';
import myImage from './my-image.jpg';
export default function MyComponent() {
return (
<Image
src={myImage}
alt="My Image"
width={500}
height={300}
/>
);
}
You can combine withImages with other Next.js plugins:
// next.config.js
const withImages = require('@opensourceframework/next-images');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
module.exports = withBundleAnalyzer(
withImages({
// your config here
})
);
next-imagesIf you're migrating from the original next-images package:
npm uninstall next-images
npm install @opensourceframework/next-images
next.config.js:// Before
const withImages = require('next-images');
// After
const withImages = require('@opensourceframework/next-images');
// Before
/// <reference types="next-images" />
// After
/// <reference types="@opensourceframework/next-images" />
withImages(options?)Creates a Next.js configuration with image handling support.
Parameters:
options (optional): Configuration options objectReturns:
Example:
import withImages from '@opensourceframework/next-images';
const config = withImages({
inlineImageLimit: 8192,
fileExtensions: ['jpg', 'png', 'svg'],
assetPrefix: 'https://cdn.example.com',
});
export default config;
The original next-images package was last updated in April 2023 and appears to be unmaintained. This fork provides:
This package is a fork of next-images originally created by Aref Aslani (twopluszero).
Original license: MIT
MIT License - see LICENSE for details.
Contributions are welcome! Please read our Contributing Guide for details.
FAQs
Import images (jpg, jpeg, png, svg, gif, ico, webp, jp2, avif) in Next.js applications. Fork of next-images with TypeScript support.
The npm package @opensourceframework/next-images receives a total of 18 weekly downloads. As such, @opensourceframework/next-images popularity was classified as not popular.
We found that @opensourceframework/next-images 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.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.