
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
react-multi-cropper
Advanced tools
A component for allowing multiple cropping regions on a single image, powered by [fabric](https://github.com/fabricjs/fabric.js).
A component for allowing multiple cropping regions on a single image, powered by fabric.
WIP: Certain aspects are in development, and may be incomplete or buggy.
It should be fine for most purposes.
yarn add react-multi-cropper fabric
yarn install
yarn start # in one terminal
yarn serve # in another
Then open http://localhost:3000 in your browser.
If 3000
is occupied, the terminal output will show you what URL the serve command is serving on.
See the examples/index.tsx file.
Draw rectangular regions on an image to obtain the selected area as a base64 encoded data URL.
Multiple regions can be obtained by drawing multiple boxes.
The component is responsive, so the image dimensions can use relative units (like %), and the cropping regions/rectangles should stay in place w.r.t. the image.
The cropping logic is aware of the device pixel ratio, so you won't get blurry crops on a MacBook or phone.
const Cropper = ({ imageUrl }: { imageUrl: string ) => {
const [boxes, setBoxes] = useState<CropperBox[]>([]);
const [imageMap, setImageMap] = useState<CropperBoxDataMap>({});
const updateBoxes = (_, __, _boxes) => setBoxes(_boxes);
return (
<div>
<MultiCrops
src={imageUrl}
zoom={1}
boxes={boxes}
onChange={updateBoxes}
onCrop={(e, map) => setImageMap(map)}
onLoad={(map) => setImageMap(map)}
/>
{boxes.map((box, i) =>
!!imageMap[box.id] && <img src={imageMap[box.id]} key={i} />
)}
</div>
);
};
In examples/index.tsx
, you'll see an implementation of reset.
const reset = () => {
setRotation(0);
setZoom(1);
resetCenter();
};
setRotation
, and setZoom
are simple state setting functions obtained from a useState
.
resetCenter
needs a few more lines.
Note: Due to the current implementation, when resetting the component you must
reset rotation
before zoom
to avoid bugs. It would be changed in the future to
use a different update mechanism.
The second argument of onLoad
provides the reset handler.
To call this from anywhere, you may want to assign this to a ref.
// Initialize a ref to store the function
const resetCenterRef = useRef(() => {});
const resetCenter = resetCenterRef.current;
// Call function anywhere
resetCenter();
// Obtain the function from onLoad
onLoad={(map, reset) => {
setImageMap(map);
resetCenterRef.current = reset;
}}
MultiCrops
componenttype CropperProps = {
cropperRef?: MutableRefObject<fabric.Canvas | null>;
src: string;
zoom?: number;
rotation?: number; // degrees
cropScale?: number; // the scale of the resultant cropped images
boxes: CropperBox[];
onChange?: UpdateFunction;
onDelete?: UpdateFunction;
onBoxMouseEnter?: UpdateFunction;
onBoxMouseLeave?: UpdateFunction;
onBoxClick?: UpdateFunction;
onLoad?: ImgOnLoadWithImageData;
onCrop?: CropTriggerFunctionWithImageData;
onZoomGesture?: (newZoom: number) => any;
containerClassName?: string;
containerStyles?: CSSProperties;
imageStyles?: CSSProperties;
cursorMode?: CropperCursorMode;
disableKeyboard?: boolean;
disableMouse?: {
all?: boolean;
zoom?: boolean;
pan?: boolean;
draw?: boolean;
};
boxInView?: { id?: string; rotate?: boolean; panInView?: boolean };
};
All the above types have been exported from the module.
onLoad
prop is optional, but useful for a few things.
img
tag.onCrop
prop if you want the default functionality to work out of the box. It will be
called when a drawing operation was completed. This will be needed if you want to receive the image payload after a cropping action was done.
onCrop
will be called when a drawing operation was completed. This will be needed if you want to receive the image payload after a cropping action was done.
CropperEvent
event that tells you all you need to know about the event that was triggered to cause this function to fire.noImage: true
key-val to it.FAQs
A component for allowing multiple cropping regions on a single image, powered by [fabric](https://github.com/fabricjs/fabric.js).
The npm package react-multi-cropper receives a total of 102 weekly downloads. As such, react-multi-cropper popularity was classified as not popular.
We found that react-multi-cropper 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.