Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced crop parameter in image for selective display of image portions #4132

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

varphone
Copy link

@varphone varphone commented May 14, 2024

Introduced crop parameter in image for selective display of image portions

This PR introduces a new crop parameter in the image function.
This allows users to selectively display portions of an image, which can be particularly useful when working with large images or when only a specific part of an image is relevant.

  • Add a new crop parameter in the image and decode function.
  • Support raster images.
  • Support vector images.
  • Support (left, top, right, bottom) tuple as the value for the crop parameter.
  • Support (left, top, width, height) tuple as the value for the crop parameter.
  • Support ratio based cropping.
    • crop: (left: 0.1, top: 0.1, right: 0.9, bottom: 0.9) will crop the image to 10% from the left, 10% from the top, 10% from the right, and 10% from the bottom.
  • Support pixel based cropping.
    • crop: (left: 100, top: 100, right: 200, bottom: 200) will crop the image to 100 pixels from the left, 100 pixels from the top, 100 pixels from the right, and 100 pixels from the bottom.
  • Support ratio and pixel based cropping together.
    • When the left or top >= 1.0, it will be considered as pixel based cropping.
    • When the right or bottom > 1.0, it will be considered as pixel based cropping.
    • crop: (left: 0.1, top: 100, right: 0.9, bottom: 200) will crop the image to 10% from the left, 100 pixels from the top, 10% from the right, and 200 pixels from the bottom.

@johannes-wolf
Copy link
Contributor

johannes-wolf commented May 14, 2024

I think, ratio based cropping should use Typst ratios: 10% instead of 0.1.

@tingerrr
Copy link
Contributor

I wonder if this should be image specific, or instead be a more general, improved clipping + place/align mechanism on containers (block/box).

It reminded me of #2709 where I attempted to change which part of an image was shown using block(clip: true) combined with align and move.

@laurmaedje
Copy link
Member

I'm also not sure if having this as an image-specific thing is great. The only thing that makes only sense in the context of images is the pixel-based clipping, but how frequently is that needed? I'm also concerned about the re-encoding. It's less efficient than path-based clipping and it's also easy to lose color-space information etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants