
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@sandeepv68/react-magnifier
Advanced tools
A simple configurable react plugin to perform image magnification.

ReactMagnifier is a simple and highly configurable react plugin to perform image magnification. This is a UMD module, so it can be used isomorphically.
Note: The name of the npm package is @sandeepv68/react-magnifier
More examples and demos can be found in example folder in the root of the repo.
Install the package from NPM using:
npm i @sandeepv68/react-magnifier
Add the component to your project using:
import ReactMagnifier from "@sandeepv68/react-magnifier";
import image from "./path/image";
<ReactMagnifier
imageUrl={image}
zoomSize={3}
imageAltText={"Some text"}
imageHeight={400}
imageWidth={600}
magnifierHeight={200}
magnifierWidth={200}
magnifierRadius={50}
magnifierBorderColor={"white"}
magnifierBorderStyle={"solid"}
magnifierBorderWidth={2}
magnifierShadow={true}
cursor={"none"}
getMagnifier={showEvent}
customImgStyles={'myClass'}
customContainerStyles={'aClass'}
/>
This component requires the following node modules as its dependency:
react - The react js core library, version (16.12.0) is used here.react-dom - The react js dom library, version(16.12.0) is used here.The following table gives all the possible input props and its default values and customizations.
| Props | Type | Required | Default | Description |
|---|---|---|---|---|
imageUrl | String | yes | empty | Url string for the image to be displayed and magnified.This is a mandatory prop. If not supplied, the component will throw ReactMagnifier Error: Image url is missing!. <ReactMagnifier imageUrl={url}/> is required. error in console, but will not break your apps ui. |
imageAltText | String | no | react-magnifier-image | The alt text value for the image |
imageHeight | Number | no | auto | Height of the image. If no value is provided, it preserves auto. |
imageWidth | Number | no | auto | Width of the image. If no value is provided, it preserves auto. |
magnifierHeight | Number | no | 100 | Height of the magnifier |
magnifierWidth | Number | no | 100 | Width of the magnifier |
magnifierRadius | Number | no | 50 | Border radius of the magnifier |
magnifierBorderColor | String | no | #000 | Border color of the magnifier |
magnifierBorderStyle | String | no | solid | Border style of the magnifier |
magnifierBorderWidth | Number | no | 3 | Border width of the magnifier |
magnifierShadow | Boolean | no | true | Box shadow for the magnifier |
cursor | String | no | none | Type of mouse cursor on magnifier |
zoomSize | Number | no | 2 | Magnification factor |
getMagnifier | Function | no | empty | Get reference to the image under magnification. The function prop returns the html element. It also includes custom events fired inside the component. |
customImgStyles | String | no | empty | White space separated CSS class names in a single string format. It can be used to override the styles of react magnifier, example : myClass newClass .. |
customContainerStyles | String | no | empty | White space separated CSS class names in a single string format. It can be used to override the styles of react magnifier, example : myClass newClass .. |
The following events are available on the ReactMagnifier component. These are available on the element returned from getMagnifier function prop
| Event | Type | Description |
|---|---|---|
magnifier-initialized | CustomEvent | This event is triggered when the magnifier is initialized for the first time. This event is triggered only once |
magnfier-moved | CustomEvent | This event is triggered anytime the magnifier is moved |
magnifier-visible | CustomEvent | This event is triggered when the magnifier is visible when hovered over the image |
magnifier-invisible | CustomEvent | This event is triggered when the magnifier is invisible when moved out of the image |
These events can be used to trigger custom logic in your app when magnifier is initialized and used.
All suggestions and pull requests are welcome. Please read the CODE_OF_CONDUCT and CONTRIBUTING files before contributing.
You can clone the repo from the following url:
git clone https://github.com/SandeepVattapparambil/react-magnify.git
Then in the repo root, you have the following npm scripts available in order of execution:
npm i
npm start
npm run test
npm run build
npm run build-tsc
npm run build-dev
npm run build-prod
You need to have Nodejs ,npm in your system as development dependency.
This project includes unit tests written in Jest testing library. Tests can be run by the npm script
npm run test

MIT License
Copyright (c) 2020 Sandeep Vattapparambil http://www.sandeepv.in
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This project is inspired from Blowup.js, but not copied or does not include any or part of it in this project.
Made with :heart: by Sandeep Vattapparambil.
All images used in demos and documentations are from Unsplash.com
FAQs
A simple configurable react plugin to perform image magnification.
We found that @sandeepv68/react-magnifier 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.