bamlab / react-native-image-resizer

🗻 Resize local images with React Native
MIT License
1.59k stars 338 forks source link

'cover' mode does not work as expected #392

Closed ionflow closed 2 months ago

ionflow commented 7 months ago

Describe the bug The definition of 'cover' in other contexts means the image is clipped to fit the container. In this library cover chooses width or height but does not respect both. In, for example, CSS the object-fit: cover property clips the left/right or top/bottom when the image content does not fit inside the container size.

It would be nice if this library at least had an additional property (crop?) to achieve this for quick cropping to the image center.

To Reproduce Steps to reproduce the behavior:

  1. Run the following on any image that doesn't have dimensions 768x512:
      ImageResizer.createResizedImage(
        media.path,
        768,
        512,
        "JPEG",
        50,
        0,
        undefined,
        false,
        {
          mode: "cover",
          onlyScaleDown: false,
        }
      )

Observed behavior The resulting image will be either 768px wide or 512px tall but not both and will maintain the original images aspect ratio. (I understand this is the documented behavior, but it is not the standard cover behavior in other contexts).

Expected behavior I would expect the resulting image to be exactly 768x512 with either top sides cropped equally or the top and bottom cropped equally.

Screenshots

Screenshot 2024-01-20 at 11 04 48 AM

Platform concerned:

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

jonxssc commented 4 months ago

Same issue still today

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 months ago

This issue has been automatically closed. Thank you for your contributions.