Skip to content

Fix incorrect dimensions when switching aspect ratios#265

Open
ranjith67 wants to merge 1 commit intospatie:mainfrom
ranjith67:fix-aspect-ratio-dimensions
Open

Fix incorrect dimensions when switching aspect ratios#265
ranjith67 wants to merge 1 commit intospatie:mainfrom
ranjith67:fix-aspect-ratio-dimensions

Conversation

@ranjith67
Copy link

Description

Fixes #257 - Incorrect width/height when switching aspect ratios

Problem

When switching aspect ratios (e.g., from 16:9 to 9:16), the calculated dimensions could exceed the original image size, resulting in invalid image requests.

Solution

  • Added constraint logic in calculateForImgTag() and calculateDimensions() methods
  • Ensures calculated dimensions never exceed original image bounds
  • Handles both portrait↔landscape ratio switching scenarios

Changes

  • Modified src/ResponsiveDimensionCalculator.php
  • Added test cases in tests/Feature/DimensionCalculatorTest.php

Testing

Added unit tests to verify:

  • Dimensions don't exceed original bounds when switching ratios
  • Both landscape→portrait and portrait→landscape scenarios work correctly

- Constrain calculated dimensions to original image bounds
- Ensure width and height never exceed source image size
- Handle both landscape->portrait and portrait->landscape switches
- Add test cases to verify dimensions stay within original bounds

Fixes spatie#257
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.

Incorrect width/height when switching aspect ratios

1 participant