Any plans to add a fit="crop" parameter to the image component? #18701
Replies: 8 comments 6 replies
-
You can achieve the a similar visual effect as The image won't actually be cropped so you're not saving on file size, but if you're looking to fit an image into a different aspect-ratio container then this may help you out. |
Beta Was this translation helpful? Give feedback.
-
Bump, this is a great idea. I hope someone sees this. |
Beta Was this translation helpful? Give feedback.
-
Any news on that? |
Beta Was this translation helpful? Give feedback.
-
👍 Terminology varies, so "crop" may take different meanings… In particular, a requirement for our CMS is to be able to select a particular region of an original image, before it is optimised (possibly different from OP's requirement, but the most relevant thread I could find). Imgix "rect"
Cloudflare "trim"
Example Next/Image Loader ImageMagick "Offsets in geometry"(eg, via the Apache module DIMS)
|
Beta Was this translation helpful? Give feedback.
-
Consider using https://images.weserv.nl/docs/crop.html#smart-crop as your image optimizer. |
Beta Was this translation helpful? Give feedback.
-
Maybe would be possible to add support for Sharp's resize API? docs: https://sharp.pixelplumbing.com/api-resize#resize I know that the M1 chip can't run Sharp so next.js added another image handling library, but Sharp is much faster on a regular Linux server, so maybe could be optional properties for dev's using the Sharp? |
Beta Was this translation helpful? Give feedback.
-
Just in case, we use imgproxy instead of next/image, which is not adding features |
Beta Was this translation helpful? Give feedback.
-
I've been working on my images optimization yesterday and i really think this is something that we need. The issueWhen using the sizes prop of the next/image component to optimize image sizes, the image optimizer only scale it down instead of cropping to the right aspect ratio. As a consequence :
I actually don't know if i should open an issue instead. Proposed solutionI don't think we need a new option for this.
So these two options should be enough to determine the correct needed aspect ratio. We could send the desired height or aspect ratio to the image optimizer so it would take it into account when resizing with Sharp. OptionsAs per the comment above, we could also add an option for the direction of the crop by using I tested a first implementation on my dev and it seems to work well. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I was wondering if there are any plans for adding a
fit=crop
property to the image component that crops images to the desired size. Other fit properties such asfill
could also be useful. For more context see: https://docs.imgix.com/apis/rendering/size/fit#crop.Are there any plans to add this feature to Next.js or will this use case always require a 3rd party loader such as Imgix or Cloudinary?
Beta Was this translation helpful? Give feedback.
All reactions