Skip to content

Conversation

@GarethSomers
Copy link
Contributor

@GarethSomers GarethSomers commented Jun 24, 2025

This PR introduces a new focalCropAndResize method to complement the existing focalCrop functionality.

Problem

Since version 3 the result of the focalCrop has changed: #245

Previously focalCrop would work similar to say ->fit(fit: Fit::Max, ...) but centered on the focal point.

Currently focalCrop accepts $cropCenterX and $cropCenterY which seems to have changed to pixels instead of percentages.

The documentation for focalCrop also appears outdated; still referencing percentages, zoom, $focalX and $focalY (instead of $cropCenterX / $cropCenterY). I can see the upgrade guide references the removal of the $zoom parameter.

Solution

To solve this problem I've created a new method focalCropAndResize and intended to match the behaviour in v2.

Unlike focalCrop it:

  • Uses percentages to describe focal point
  • First crops the entire photo using the intended aspect ratio similar to Fit:Max, and using the provided focal point as an anchor.
  • It will then resize the image to the intended width / height.

This is useful when you want to preserve the full context of an image while still enforcing a specific aspect ratio around a focal point.

Comparison

Original
Focal point @ 0:0
Size: 1600x1600

Screenshot 2025-06-24 at 3 49 29 pm

focalCrop

Screenshot 2025-06-24 at 3 52 20 pm

Screenshot 2025-06-24 at 3 51 02 pm

focalCropAndResize

Screenshot 2025-06-24 at 3 51 50 pm

Screenshot 2025-06-24 at 3 50 44 pm

@freekmurze freekmurze requested a review from timvandijck June 27, 2025 08:06
@timvandijck
Copy link
Member

Nice PR thank you! Also thanks for the examples in the PR!

@timvandijck timvandijck merged commit 183aaad into spatie:main Jun 27, 2025
4 checks passed
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.

2 participants